am15h / object_detection_flutter

Truly realtime object-detection in flutter
188 stars 113 forks source link

Ensure isolates are ready before using them with the camera #13

Closed tomcurran closed 3 years ago

tomcurran commented 3 years ago

Moved all the initState code into an async method to be able to call await on IsolateUtils.start() and ensure it's fully set up before proceeding to initialise the camera. The cameras callbacks used the isolate which was causing a crash.

mlopez0 commented 3 years ago

Awesome @tomcurran I was trying to solve this issue for a while, but I wasn't sure on how to approach the problem.

This issue affect Android devices as well, I just tried your change in an Android device and I get the following error.

Any idea why this happens?

Screen Shot 2021-03-31 at 8 07 52 AM

tomcurran commented 3 years ago

Not sure @mlopez0 I've only got one Android device (Pixel 5) and I'm not getting the error. I don't know much about the Isolate stuff. I just rearranged the calls so IsolateUtils.start() would fully complete before any of the camera initialisation code would execute. Before both were happening in parrallel.

tomcurran commented 3 years ago

@mlopez0 would you be able to explain the purpose of the isolate stuff? That might help me understand it and be able to work on a fix. Happy to continue over another messaging platform if that's easier

tomcurran commented 3 years ago

@mlopez0 I was experimenting with channels to do something similar. Let me know what you think of this https://github.com/tomcurran/object_detection_flutter/tree/feature/isolate2

mlopez0 commented 3 years ago

Not sure @mlopez0 I've only got one Android device (Pixel 5) and I'm not getting the error. I don't know much about the Isolate stuff. I just rearranged the calls so IsolateUtils.start() would fully complete before any of the camera initialisation code would execute. Before both were happening in parrallel.

My bad @tomcurran , I tested your commit with a heavily modified version of this project. I had an extra isolateUtils.start(); which caused the mentioned error.

I re-tested in a clean version of this project and everything run great!.

@mlopez0 I was experimenting with channels to do something similar. Let me know what you think of this https://github.com/tomcurran/object_detection_flutter/tree/feature/isolate2

Wow, I checked your code, I will test it. I've never worked with channels before, thanks for sharing this approach.

tomcurran commented 3 years ago

@mlopez0 good to know the original changes weren't causing any issues :)

am15h commented 3 years ago

Thanks a lot, @tomcurran for the PR.