juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hot restart - camera no longer usable

EArminjon opened this issue · comments

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

commented

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

mobile_scanner: ^5.0.0

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

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

@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.

Hello @navaronbracke,

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

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

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

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.

commented

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.

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 : flutter/flutter#10437)

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.

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

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.