Skip to content

EXC_BAD_ACCESS crash in photo_manager beginning with 3.5.0 #1322

@btietz

Description

@btietz

Version

3.5.0

Platforms

iOS

Device Model

iPhone 16 Pro

flutter info

I don't care about chrome dev, so not applicable but here's the flutter doctor -v output as requested:

[✓] Flutter (Channel stable, 3.35.7, on macOS 15.7.2 24G325 darwin-x64, locale en-US) [456ms]
    • Flutter version 3.35.7 on channel stable at /Users/briantietz/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision adc9010625 (3 weeks ago), 2025-10-21 14:16:03 -0400
    • Engine revision 035316565a
    • Dart version 3.9.2
    • DevTools version 2.48.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
      cli-animations, enable-lldb-debugging

[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [4.1s]
    • Android SDK at /Users/briantietz/Library/Android/sdk
    • Emulator version 36.1.9.0 (build_id 13823996) (CL:N/A)
    • Platform android-36, build-tools 36.1.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,465ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    [22ms]
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2024.3) [21ms]
    • 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 21.0.6+-13368085-b895.109)

[✓] VS Code (version 1.105.1) [17ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.122.0

[✓] Connected device (2 available) [6.7s]
    • iPhone 16 Pro (mobile) • 3C4F76CE-DE4D-47BC-A646-DACFF993F641 • ios        • com.apple.CoreSimulator.SimRuntime.iOS-18-5
      (simulator)
    • macOS (desktop)        • macos                                • darwin-x64 • macOS 15.7.2 24G325 darwin-x64

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

! Doctor found issues in 1 category.

How to reproduce?

I am using the following code for image import selection. It's a widget that I embed in a bottom sheet. Right from the get-go, I was seeing hard crashes. No exception trace in the flutter / Visual Studio Code debugger, just the app stone cold killed. So hard crash in native code. I tracked this as far as I can before reporting.

It was introduced in version 3.5.0. I am not seeing it with 3.4.0 after fairly exhaustive testing.

The Visual Studio Code debugger provides no useful information, it's just a hard stop, but under Xcode I get a better view. The hard crash is in PMManager as far as I can tell. Assembly view has no source, just movq 0x20(%rax), %rcx. I see source code two stack frames above, and it's here:

[self.cachingManager requestImageForAsset:asset targetSize:CGSizeMake(width, height) (etc...)

Logs

Example code (optional)

// Dart SDK imports:
import "dart:typed_data";
import "dart:io";

// Dart package imports:

// Flutter SDK imports:
import "package:flutter/material.dart";

// Flutter package imports:
import "package:photo_manager/photo_manager.dart";

class PhotoGalleryGrid extends StatefulWidget {
  final ValueChanged<String> onImageSelected;

  const PhotoGalleryGrid({super.key, required this.onImageSelected});

  @override
  State<PhotoGalleryGrid> createState() => _PhotoGalleryGridState();
}

class _PhotoGalleryGridState extends State<PhotoGalleryGrid> {
  List<AssetEntity> assets = <AssetEntity>[];
  int currentPage = 0;
  bool isLoading = false;

  @override
  void initState() {
    super.initState();
    _loadMoreAssets();
  }

  Future<void> _loadMoreAssets() async {
    if (isLoading) return;
    setState(() {
      isLoading = true;
    });

    final List<AssetPathEntity> paths = await PhotoManager.getAssetPathList(type: RequestType.image);

    if (paths.isNotEmpty) {
      final AssetPathEntity recentAlbum = paths.first;
      final List<AssetEntity> newAssets = await recentAlbum.getAssetListPaged(page: currentPage, size: 20);

      setState(() {
        assets.addAll(newAssets);
        currentPage++;
        isLoading = false;
      });
    } else {
      setState(() {
        isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 4,
        crossAxisSpacing: 4.0,
        mainAxisSpacing: 4.0,
      ),
      itemCount: assets.length + (isLoading ? 1 : 0),
      itemBuilder: (BuildContext context, int index) {
        if (index == assets.length) {
          return Center(child: CircularProgressIndicator());
        }

        final AssetEntity asset = assets[index];
        return GestureDetector(
          onTap: () async {
            final File? file = await asset.file;
            if (file != null) {
              widget.onImageSelected(file.path);
            }
          },
          child: FutureBuilder<Uint8List?>(
            key: ValueKey(asset.id),
            future: asset.thumbnailDataWithSize(const ThumbnailSize(200, 200)),
            builder: (BuildContext context, AsyncSnapshot<Uint8List?> snapshot) {
              if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) {
                return Image.memory(snapshot.data!, fit: BoxFit.cover);
              }
              // Placeholder while the thumbnail loads
              return Container(
                color: Colors.grey,
                child: Center(child: Icon(Icons.image, color: Colors.grey)),
              );
            },
          ),
        );
      },
    );
  }
}

Contact

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions