g123k / flutter_torch_compat

A plugin to enable or disable the torch of a device that works both on Android (including Android 4.x) and iOS.
https://pub.dev/packages/torch_compat
Apache License 2.0
7 stars 22 forks source link

Background Android crash #23

Open ikbendewilliam opened 1 year ago

ikbendewilliam commented 1 year ago

We need to do some background stuff in our app, for this we use the background_location_tracker package which allows us to use packages aswel in the background. This is required for some different stuff, but causes an issue with your package. When in background, everything works fine, but when we want to close the isolate (since we're done), we get the following error:

kotlin.UninitializedPropertyAccessException: lateinit property torchImpl has not been initialized
...
at fr.g123k.torch_compat.TorchCompatPlugin.onDetachedFromEngine(TorchCompatPlugin.kt:107)

This blocks the cleanup process causing a memory leak and after a minute or so a error: Out of memory.

Full error ## Full error ``` I/flutter (10394): locationUpdate: {lat: 50, lon: 4, logging_enabled: true} I/flutter (10394): Got data: Instance of 'BackgroundLocationUpdateData' at time 2022-11-02 11:15:56.130855 D/BackgroundManager(10394): Got success, destroy engine! D/FlutterGeolocator(10394): Disposing Geolocator services E/FlutterGeolocator(10394): Geolocator position updates stopped D/FlutterGeolocator(10394): Stopping location service. E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): Failed to handle method call result E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): kotlin.UninitializedPropertyAccessException: lateinit property torchImpl has not been initialized E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at fr.g123k.torch_compat.TorchCompatPlugin.onDetachedFromEngine(TorchCompatPlugin.kt:107) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:270) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:280) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:288) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:121) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:425) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at com.icapps.background_location_tracker.flutter.FlutterBackgroundManager$handleInitialized$1.success(FlutterBackgroundManager.kt:66) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.plugin.common.MethodChannel$IncomingResultHandler.reply(MethodChannel.java:239) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.embedding.engine.dart.DartMessenger.handlePlatformMessageResponse(DartMessenger.java:375) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessageResponse(FlutterJNI.java:1003) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at android.os.MessageQueue.next(MessageQueue.java:339) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at android.os.Looper.loopOnce(Looper.java:179) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at android.os.Looper.loop(Looper.java:344) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at android.app.ActivityThread.main(ActivityThread.java:8212) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) E/MethodChannel#com.icapps.background_location_tracker/background_channel(10394): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) ```