Skip to content

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

@radivojeostojic

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.

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