Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopping the controller crashes the app #5

Closed
elias8 opened this issue Feb 18, 2022 · 9 comments · Fixed by #21
Closed

Stopping the controller crashes the app #5

elias8 opened this issue Feb 18, 2022 · 9 comments · Fixed by #21
Labels
bug Something isn't working
Milestone

Comments

@elias8
Copy link
Contributor

elias8 commented Feb 18, 2022

Platform: iOS
Version: ^0.0.3

Crash log when `MobileScanerController.stop()` is called.

Runner was compiled with optimization - stepping may behave oddly; variables may not be available.
thread # 1, queue = 'com.apple.main-thread', stop reason = Swift runtime failure: Unexpectedly found nil while implicitly unwrapping an Optional value
frame # 1: 0x00000001056cea70 Runner specialized SwiftMobileScannerPlugin.stop(self=0x000000028252de00) at SwiftMobileScannerPlugin.swift:239:9 [opt]
236 }
237
238 func stop(_ result: FlutterResult) {
-> 239 captureSession.stopRunning()
^
240 for input in captureSession.inputs {
241 captureSession.removeInput(input)
242 }
Target 0: (Runner) stopped.

I have tried to add a null check on the captureSession and other variables that are causing the crash and it fixes the crash, but then it won't stop scanning.

Flutter Doctor Doctor summary (to see all details, run flutter doctor -v):
  • [✓] Flutter (Channel stable, 2.10.1, on macOS 12.1 21C52 darwin-x64, locale en-ET)
  • [✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
  • [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
  • [✓] Chrome - develop for the web
  • [✓] Android Studio (version 2021.1)
  • [✓] IntelliJ IDEA Community Edition (version 2021.3.1)
  • [✓] VS Code (version 1.64.2)
  • [✓] Connected device (4 available)
  • [✓] HTTP Host Availability
@starteNCS
Copy link

Also, I my case the app crashes when just hot reloading with the camera open.

@juliansteenbakker
Copy link
Owner

Fixed with #6 and released in v0.1.0. Thanks for reporting!

@elias8
Copy link
Contributor Author

elias8 commented Feb 21, 2022

@juliansteenbakker, #6 doesn't solve this issue, and it persists in the new release. It seems to happen due to trying to access a nil value inside the stop method. And while adding a null check fixes the crash, calling mobileScannerController.stop() after that won't actually stop the scanning.

@juliansteenbakker
Copy link
Owner

Oh my bad, i didn't test it yet but i will later today.

@juliansteenbakker juliansteenbakker added this to the 0.1.2 milestone Feb 21, 2022
@juliansteenbakker juliansteenbakker added the bug Something isn't working label Feb 21, 2022
@blue492
Copy link

blue492 commented Feb 22, 2022

Same issue here when using stop function in the controller in real Android device

E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): Failed to handle method call
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): java.lang.NullPointerException
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at dev.steenbakker.mobile_scanner.MobileScanner.stop(MobileScanner.kt:202)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at dev.steenbakker.mobile_scanner.MobileScanner.onMethodCall(MobileScanner.kt:52)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:320)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at android.os.Handler.handleCallback(Handler.java:873)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at android.os.Looper.loop(Looper.java:214)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at android.app.ActivityThread.main(ActivityThread.java:7050)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/MethodChannel#dev.steenbakker.mobile_scanner/scanner/method(13457): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
E/flutter (13457): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(error, null, null, java.lang.NullPointerException
E/flutter (13457): 	at dev.steenbakker.mobile_scanner.MobileScanner.stop(MobileScanner.kt:202)
E/flutter (13457): 	at dev.steenbakker.mobile_scanner.MobileScanner.onMethodCall(MobileScanner.kt:52)
E/flutter (13457): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (13457): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter (13457): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:320)
E/flutter (13457): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (13457): 	at android.os.Handler.handleCallback(Handler.java:873)
E/flutter (13457): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (13457): 	at android.os.Looper.loop(Looper.java:214)
E/flutter (13457): 	at android.app.ActivityThread.main(ActivityThread.java:7050)
E/flutter (13457): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (13457): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
E/flutter (13457): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
E/flutter (13457): )
E/flutter (13457): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (13457): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter (13457): <asynchronous suspension>
E/flutter (13457): #2      MobileScannerController.stop (package:mobile_scanner/src/mobile_scanner_controller.dart:149:32)
E/flutter (13457): <asynchronous suspension>
E/flutter (13457): 
E/BufferQueueProducer(13457): [SurfaceTexture-0-13457-1] queueBuffer: BufferQueue has been abandoned
E/BufferQueueProducer(13457): [SurfaceTexture-0-13457-1] queueBuffer: BufferQueue has been abandoned
E/BufferQueueProducer(13457): [SurfaceTexture-0-13457-1] queueBuffer: BufferQueue has been abandoned
E/BufferQueueProducer(13457): [SurfaceTexture-0-13457-1] queueBuffer: BufferQueue has been abandoned
D/UseCaseAttachState(13457): Active and attached use case: [] for camera: 0
D/DeferrableSurface(13457): use count-1,  useCount=0 closed=true androidx.camera.core.SurfaceRequest$2@5132faf
D/DeferrableSurface(13457): Surface no longer in use[total_surfaces=2, used_surfaces=1](androidx.camera.core.SurfaceRequest$2@5132faf}
D/DeferrableSurface(13457): Surface terminated[total_surfaces=1, used_surfaces=1](androidx.camera.core.SurfaceRequest$2@5132faf}
D/DeferrableSurface(13457): use count-1,  useCount=0 closed=true androidx.camera.core.impl.ImmediateSurface@d0c629a
D/DeferrableSurface(13457): Surface no longer in use[total_surfaces=1, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface@d0c629a}
D/DeferrableSurface(13457): Surface terminated[total_surfaces=0, used_surfaces=0](androidx.camera.core.impl.ImmediateSurface@d0c629a}
D/Camera2CameraImpl(13457): {Camera@fb023e9[id=0]} CameraDevice.onClosed()
D/Camera2CameraImpl(13457): {Camera@fb023e9[id=0]} Transitioning camera internal state: CLOSING --> INITIALIZED
D/CameraStateRegistry(13457): Recalculating open cameras:
D/CameraStateRegistry(13457): Camera                                       State                 
D/CameraStateRegistry(13457): -------------------------------------------------------------------
D/CameraStateRegistry(13457): Camera@fb023e9[id=0]                         CLOSED                
D/CameraStateRegistry(13457): Camera@7e2392b[id=1]                         UNKNOWN               
D/CameraStateRegistry(13457): -------------------------------------------------------------------
D/CameraStateRegistry(13457): Open count: 0 (Max allowed: 1)
D/CameraStateMachine(13457): New public camera state CameraState{type=CLOSED, error=null} from CLOSED and null
D/CameraStateMachine(13457): Publishing new public camera state CameraState{type=CLOSED, error=null}

@al-bezd
Copy link

al-bezd commented Feb 22, 2022

When running in the emulator, some kind of nightmare happens, the emulator seems to report control information and immediately reset it, stack overflow detection effect, multiple method call and reset in the emulator

@juliansteenbakker
Copy link
Owner

I did some testing using a Pixel 4a 5G and i can sucessfully stop and start the camera multiple times. There are however errors thrown if u call stop while the camera is already stopped. Also, starting the camera 2 times crashes the app. I am working on some fixes for this and will update this when ready.

@blue492
Copy link

blue492 commented Feb 23, 2022

I did some testing using a Pixel 4a 5G and i can sucessfully stop and start the camera multiple times. There are however errors thrown if u call stop while the camera is already stopped. Also, starting the camera 2 times crashes the app. I am working on some fixes for this and will update this when ready.

Bug example: I open the scanning page which open the camera, and then try to close the page by Navigator.pop(context); the camera and flash still be open, and when I open scanning page the app crashes. I added controller.stop(); before Navigator.pop(context); But in some devices and platforms you can go back by swiping without clicking on any button in the app.

Solution: Is it possible to add an option to stop the camera after a duration which we can change the duration manually in the code?

@jahnli
Copy link

jahnli commented Mar 2, 2022

@juliansteenbakker Thank you very much for your contribution. In 0.1.2, cameracontroller.stop will not stop scanning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants