Skip to content

[camera][iOS] using startImageStream() can lead to memory crash on iOS #97941

@renanyoy

Description

@renanyoy

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. memory problems..
Code sample
    final controller = CameraController(camera, ResolutionPreset.max,
        enableAudio: false, imageFormatGroup: ImageFormatGroup.bgra8888);
    await controller.initialize();
    controller.lockCaptureOrientation(DeviceOrientation.portraitUp);
      controller.startImageStream((image) async {
        if (paused) return;
        //this.image = image;
      });
Logs
[ +322 ms] flutter: |L2K|camera initialized
[+1156 ms] [ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke
[ +434 ms] *** Terminating app due to uncaught exception 'NSMallocException', reason: 'Failed to grow buffer'
[        ] *** First throw call stack:
[        ] (0x18091d0fc 0x199169d64 0x180a2ab24 0x180a22e10 0x1808b733c 0x1820e1ad8 0x1820dd764 0x182125870 0x182127fa8 0x18210d69c 0x10f30d234 0x10f30d044 0x10f30d234 0x10f30d788 0x10f30af84 0x10c445528 0x18058d924 0x18058f670 0x18059db70 0x1808d5d84 0x18088ff5c 0x1808a3468 0x19c44338c
0x1832465d0 0x182fc4f74 0x10404085c 0x10b795aa4)
[        ] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** NSAllocateMemoryPages(33177600) failed'
[        ] *** First throw call stack:
[        ] (0x18091d0fc 0x199169d64 0x182127f30 0x1820d3260 0x1820e69e0 0x10c444ab0 0x19f304124 0x19f2ee27c 0x19f534098 0x19f6ea6b8 0x18058f670 0x180592b44 0x1805a5c48 0x180596ccc 0x180597968 0x1805a21b8 0x1f13ab0f4 0x1f13aae94)
[        ] libc++abi: terminating with uncaught exception of type NSException
[        ] libc++abi: terminating with uncaught exception of type NSException
[ +305 ms] Process 4459 stopped
[        ] * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
[        ]     frame #0: 0x00000001b7e79964 libsystem_kernel.dylib`__pthread_kill + 8
[        ] libsystem_kernel.dylib`__pthread_kill:
[        ] ->  0x1b7e79964 <+8>:  b.lo   0x1b7e79984               ; <+40>
[        ]     0x1b7e79968 <+12>: pacibsp 
[        ]     0x1b7e7996c <+16>: stp    x29, x30, [sp, #-0x10]!
[        ]     0x1b7e79970 <+20>: mov    x29, sp
[        ] Target 0: (Runner) stopped.
[        ] ios-deploy exited with code 0
[ +157 ms] Service protocol connection closed.
[        ] Lost connection to device.
[✓] Flutter (Channel stable, 2.10.0, on macOS 12.1 21C52 darwin-x64, locale en-FR)
    • Flutter version 2.10.0 at /Users/renanyoy/code/sdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (5 days ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/renanyoy/Library/Android/sdk
    • Platform android-31, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.10.0.rc.1

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

[✓] Android Studio (version 2020.3)
    • 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.10+0-b96-7281165)

[✓] VS Code (version 1.63.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (2 available)
    • Renaniphone (mobile) • 00008020-000640992209002E • ios        • iOS 15.3 19D50
    • macOS (desktop)      • macos                     • darwin-x64 • macOS 12.1 21C52 darwin-x64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: fatal crashCrashes that terminate the processfound in release: 2.10Found to occur in 2.10found in release: 2.11Found to occur in 2.11has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.perf: memoryPerformance issues related to memoryplatform-iosiOS applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions