Skip to content

FLTImagePickerImageUtil crash: UIGraphicsBeginImageContext() failed to allocate CGBitampContext #144602

Closed
flutter/packages
#6285

Description

@radivojeostojic

Steps to reproduce

Replicating the issue locally is challenging. However, there has been a noticeable uptick in occurrences reported on Crashlytics among iOS users running iOS 17 and above. The image_picker version that we are currently using is 1.0.5, but we also noticed these issues in earlier versions.

Expected results

We shouldn't see these issues in Crashlytics.

Actual results

We've observed reports of this issue from a relatively large number of our users on Crashlytics.

Code sample

Here is the example how we use ImagePicker

Code sample
    final pickedFile = await picker.pickImage(
      // use the camera if available, else fall back to gallery
      source: (cameras.isNotEmpty) ? ImageSource.camera : ImageSource.gallery,
      preferredCameraDevice: CameraDevice.rear,
      maxHeight: 1024,
      maxWidth: 1024,
      imageQuality: 60,
    );

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
+[FLTImagePickerImageUtil scaledImage:maxWidth:maxHeight:isMetadataAvailable:]

image_picker_ios:
FLTImagePickerImageUtil.m - Line 74
+[FLTImagePickerImageUtil scaledImage:maxWidth:maxHeight:isMetadataAvailable:] + 74```


Fatal Exception: NSInternalInconsistencyException
UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=1.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.
</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[!] Flutter (Channel [user-branch], 3.16.9, on macOS 14.0 23A344 darwin-arm64,
    locale en-RS)
    ! Flutter version 3.16.9 on channel [user-branch] at
      /Users/radivojeostojic/Documents/development/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an
      official channel.
      If that doesn't fix the issue, reinstall Flutter by following
      instructions at https://flutter.dev/docs/get-started/install.
    ! Warning: `dart` on your path resolves to
      /opt/homebrew/Cellar/dart/2.17.6/libexec/bin/dart, which is not inside
      your current Flutter SDK checkout at
      /Users/radivojeostojic/Documents/development/flutter. Consider adding
      /Users/radivojeostojic/Documents/development/flutter/bin to the front of
      your path.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss
      this error.
    • Framework revision 41456452f2 (6 weeks ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version
    33.0.1)
    • Android SDK at /Users/radivojeostojic/Library/Android/sdk
    • Platform android-34, build-tools 33.0.1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.68.1)
    • VS Code at /Users/radivojeostojic/Downloads/Visual Studio
      Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (5 available)
    • SM G955U1 (mobile)          • 988bdc37395638324a        • android-arm64  • Android 9 (API 28)
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 12 (API 31) (emulator)
    • Radivoje’s iPhone (mobile)  • 00008110-000159280100401E • ios            • iOS 17.3.1 21D61
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 122.0.6261.94

[✓] Network resources
    • All expected network resources are available.

Activity

  1. darshankawar commented on Mar 6, 2024

    @darshankawar
    Member

    Thanks for the report @radivojeostojic

    Fatal Exception: NSInternalInconsistencyException
    UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={0, 0}, scale=1.000000, bitmapInfo=0x2002. Use UIGraphicsImageRenderer to avoid this assert.
    </details>
    

    Looks like this could be specific to xcode + ios version combination, as I see below similar issues logged for different frameworks:

    xamarin/Xamarin.Forms#15827
    react-native-linear-gradient/react-native-linear-gradient#637

    Apple forum: https://forums.developer.apple.com/forums/thread/733326

    Based on the report, I'll label this for team's attention / tracking.

  2. added
    platform-iosiOS applications specifically
    packageflutter/packages repository. See also p: labels.
    c: fatal crashCrashes that terminate the process
    t: xcode"xcodebuild" on iOS and general Xcode project management
    e: OS-version specificAffects only some versions of the relevant operating system
    team-iosOwned by iOS platform team
    needs repro infoAutomated crash report whose cause isn't yet known
    and removed
    in triagePresently being triaged by the triage team
    on Mar 6, 2024
  3. changed the title [-]FLTImagePickerImageUtil issue reported on Crashlytics [/-] [+]FLTImagePickerImageUtil crash: UIGraphicsBeginImageContext() failed to allocate CGBitampContext[/+] on Mar 6, 2024
  4. added
    P2Important issues not at the top of the work list
    on Mar 6, 2024
  5. removed
    t: xcode"xcodebuild" on iOS and general Xcode project management
    P2Important issues not at the top of the work list
    on Mar 6, 2024
  6. added
    t: xcode"xcodebuild" on iOS and general Xcode project management
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    on Mar 6, 2024
  7. removed
    t: xcode"xcodebuild" on iOS and general Xcode project management
    on Mar 7, 2024
  8. jmagman commented on Mar 7, 2024

    @jmagman
    Member

    Maybe a regression from flutter/packages#5527? cc @tarrinneal

  9. tarrinneal commented on Mar 7, 2024

    @tarrinneal
    Contributor

    Maybe a regression from flutter/packages#5527? cc @tarrinneal

    Seems unlikely, that change didn't touch any code that should be effecting allocation (or anything that could cause crashes imo)

  10. jmagman commented on Mar 8, 2024

    @jmagman
    Member
  11. added
    r: fixedIssue is closed as already fixed in a newer version
    on Mar 14, 2024
  12. github-actions commented on Mar 28, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  13. locked as resolved and limited conversation to collaborators on Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: fatal crashCrashes that terminate the processe: OS-version specificAffects only some versions of the relevant operating systemneeds repro infoAutomated crash report whose cause isn't yet knownp: image_pickerThe Image Picker plugin.packageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions