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
744 stars 444 forks source link

Hot restart - camera no longer usable #1037

Open EArminjon opened 3 weeks ago

EArminjon commented 3 weeks ago

If i do a hot restart while camera is displayed, I no longer have the possibility to use it until app is closed.

MobileScannerException: code genericError, message: Called start() while already started

mobile_scanner: ^5.0.1

dcarv01 commented 3 weeks ago

Here too, I need to reinstall the app. If I close and open it again, the same error persists.

mobile_scanner: ^5.0.0

EArminjon commented 3 weeks ago

@dcarv01 can you tell me your device + os, that's weird to uninstall as a unique solution.

laterdayi commented 3 weeks ago

same https://github.com/juliansteenbakker/mobile_scanner/issues/773#issuecomment-2072972048

EArminjon commented 3 weeks ago

Personally I didn't have an issue with the hot reload, only the hot restart.

navaronbracke commented 3 weeks ago

@EArminjon We indeed need to provide better support for hot reload. I filed #773 for that in the past.

We might be able to use the reassemble hook from the framework, but I'm not sure.

I'm going to close this issue in favor of #773 so that we have only one tracking issue.

EArminjon commented 3 weeks ago

Hello @navaronbracke,

I didn't talk about hot reload but hot restart, can you confirm that your answer fit for hot restart ?

navaronbracke commented 3 weeks ago

Hot restart is a full restart of the app state. Perhaps if we fix hot reload, we might also fix it for hot restart?

EArminjon commented 3 weeks ago

Personally i didn't have any issue around hot reload, only hot restart for both Android and iOS.

EArminjon commented 3 weeks ago

To be more precise : on hot restart camera work but not the preview on flutter side (black screen) : i can scan some document despite my black screen.

dcarv01 commented 3 weeks ago

I too have problem only with Hot restart, hot reload is ok.

@dcarv01 can you tell me your device + os, that's weird to uninstall as a unique solution.

I tried again, and there was no need to uninstall, perhaps I was mistaken.

EArminjon commented 3 weeks ago

A hint :

I've removed some protections to force call the stop() method from MobileScanner.swift before instantiate the MobileScannerController() on my dart side. I've added some protection inside this stop() method to only process some action if the variable is not nil.

Result :

On hot restart camera works.

Limit :

I can see the green camera OS icon after the hot restart, so camera is still used by something. Not normal.

Conclusion :

We need to find a way on hot restart to remove used resources or on start() to do so.

(maybe this topic can help once fixed : https://github.com/flutter/flutter/issues/10437)

EArminjon commented 3 weeks ago

On our app, we always dispose the MobileScannerController when we need to do 'pause' or to open a new page which potentially will contain an other MobileScannerController().

We use visibility detector to start() the camera and we delay it a bit to let other MobileScannerController() instance the time to dispose. That's an other issue which i will open later because it can be fixed maybe by this issue.

EArminjon commented 3 weeks ago

Based on these observations and as it's not hot reload directly linked, I think we can reopen :/ ?

navaronbracke commented 3 weeks ago

I will keep this issue open for tracking. Perhaps if we fix the hot reload support, the other issue goes away, although I am not certain.