juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
756 stars 446 forks source link

Crash when run on Mac (Designed for iPad) #863

Open Maatteogekko opened 6 months ago

Maatteogekko commented 6 months ago

Opening the scanner when the app is being run with the target My Mac (Designed for iPad) from Xcode crashes the app with the following exception.

CMIO_DAL_PlugInManagement.cpp:913:CreatePlugIn Could not find plugin with kCMIOHardwarePlugInTypeID
<<<< FigCaptureCameraParameters >>>> Fig assert: "success" at bail (FigCaptureCameraParameters.m:249) - (err=0)
<<<< FigCaptureCameraParameters >>>> Fig assert: "success" at bail (FigCaptureCameraParameters.m:249) - (err=0)
-[MTLDebugDevice newTextureWithDescriptor:iosurface:plane:]:2641: failed assertion `Texture Descriptor Validation
IOSurface textures must use MTLStorageModeShared
'

I am on a Mac M1 Pro, running with Flutter 3.13.8, mobile_scanner 3.5.2

navaronbracke commented 6 months ago

Does this occur if you run it natively on MacOS (flutter run -d macos) ? And what MacOS / XCode version do you have?

Maatteogekko commented 6 months ago

Xcode version: 15.0.1 (15A507), MacOS version: 14.0 (23A344). Running natively the crash does not happen.

navaronbracke commented 6 months ago

I'll try to see if this reproduces locally with only a texture, as we do not directly create a MTLTexture in the plugin.

cristianms commented 6 months ago

i'm having a similar issue here, the app crashes and is closed automatically after at about 50 seconds after opened, without me take any action...

Mac Ventura 13.6.1 XCode 15.0.1 Flutter 3.13.9 mobile_scanner 3.5.2

it happened on real iPad device (iOS 12) and in iPad simulator (iOS 14.3) nothing were logged on flutter console...

i appreciate any help

navaronbracke commented 6 months ago

Aha, then it might be an iPad-specific issue. I'll try to get hold of one to see if I can repro the crash.

Maatteogekko commented 6 months ago

@navaronbracke is there anything I can do to help with the reproduction?

navaronbracke commented 6 months ago

@Maatteogekko If you set up a fresh Flutter project that sets up a Texture, using the TextureRegistry (you can look at how the plugin does it), and then run it with the "Mac (Designed for IPad)" target, does it crash as well?

Because then this is a Flutter bug and we should report it there. That's the only thing I can think of to be honest.

Maatteogekko commented 6 months ago

Good news! Turns out that the problem is caused by the Metal API Validation debugging diagnostic. The solution provided here fixed it for me.

Maybe it's worth adding a disclaimer in the README

navaronbracke commented 6 months ago

Interesting, perhaps the TextureRegistry hits a validation error there.

Since this probably points to a bug in how the MTLTexture is used (hence the validation error), I wouldn't directly put it in the README, as I think we should investigate upstream in flutter/flutter so that the fix for the actual issue can land in flutter/engine later.

Good find!

navaronbracke commented 6 months ago

@Maatteogekko does this crash happen when you switch to Flutter's master channel?

See https://github.com/flutter/engine/blob/4f217e1f9afed45f50454de68fe4b8ea6a42a4da/impeller/renderer/backend/metal/allocator_mtl.mm#L143-L173 for context in the engine.

navaronbracke commented 6 months ago

@Maatteogekko and @cristianms Could you provide the output of flutter doctor -v ? This will help me with the full setup information to investigate further. In the meantime, I filed https://github.com/flutter/flutter/issues/139147 to track upstream.

Maatteogekko commented 6 months ago
[✓] Flutter (Channel stable, 3.13.8, on macOS 14.1.1 23B81 darwin-arm64, locale en-IT)
    • Flutter version 3.13.8 on channel stable at /Users/gekko/fvm/versions/3.13.8
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6c4930c4ac (6 weeks ago), 2023-10-18 10:57:55 -0500
    • Engine revision 767d8c75e8
    • Dart version 3.1.4
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc4)
    • Android SDK at /Users/gekko/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0-rc4
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2022.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 17.0.6+0-17.0.6b829.9-10027231)

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

[✓] Connected device (3 available)
    • Matteo’s iPhone (mobile) • 00008101-0019288C1E30001E • ios            • iOS 17.1.1 21B91
    • macOS (desktop)          • macos                     • darwin-arm64   • macOS 14.1.1 23B81 darwin-arm64
    • Chrome (web)             • chrome                    • web-javascript • Google Chrome 119.0.6045.159

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

• No issues found!
Maatteogekko commented 6 months ago

The issue still happens on master btw

cristianms commented 6 months ago

[!] Flutter (Channel stable, 3.13.9, on macOS 13.6.1 22G313 darwin-x64, locale pt-BR) • Flutter version 3.13.9 on channel stable at /Users/timeweb/fvm/versions/3.13.9 ! Warning: dart on your path resolves to /usr/local/Cellar/dart/3.0.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/timeweb/fvm/versions/3.13.9. Consider adding /Users/timeweb/fvm/versions/3.13.9/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision d211f42860 (5 weeks ago), 2023-10-25 13:42:25 -0700 • Engine revision 0545f8705d • Dart version 3.1.5 • DevTools version 2.25.0 • 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 30.0.2) • Android SDK at /Users/timeweb/Library/Android/sdk ✗ cmdline-tools component is missing Run path/to/sdkmanager --install "cmdline-tools;latest" See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

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

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

[!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

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

[✓] Connected device (3 available) • iPad Pro (9.7-inch) (mobile) • 73C4A40D-1414-4733-AB16-CCDE1FB31D66 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • macOS 13.6.1 22G313 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.159 ! Error: Browsing on the local area network for iPhone de Rech. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27)

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

PS: I'm not using Android on Mac, only iOS, this issue that i was telling you doesn't happen in newer iOS versions.

cristianms commented 5 months ago

Hello! Is there any news/update on this issue by any chance?

navaronbracke commented 5 months ago

This was reported upstream, as it is a bug with Flutter's Texture allocator for Metal.

I'll try to get a minimal reproduction sample so that it can be investigated over there.

navaronbracke commented 3 weeks ago

@Maatteogekko FYI: this is being tracked upstream in https://github.com/flutter/flutter/issues/141719 as that is an umbrella issue for the wider feature