Knightro63 / flutter_angle

Flutters Almost Native Graphics Layer Engine.
4 stars 1 forks source link

LateInitializationError: Field 'worker' has not been initialized. #4

Open alexgrusu opened 2 months ago

alexgrusu commented 2 months ago

I believe this can occur when we create a texture, the following method doesn't complete in time

    final result = await _channel.invokeMethod('createTexture', {"width": width, "height": height,});

and next, we call deleteTexture.

The flow is something like this

  1. call static Future<FlutterAngleTexture> createTexture(AngleOptions options)
  2. line 294 awaited -> final result = await _channel.invokeMethod('createTexture', {"width": width, "height": height,});
  3. call deleteTexture
  4. line 388 call -> worker.dispose();
  5. back to createTexture -> we get the worker.

I have in mind a fix and I can raise a PR. Let me know your thoughts and if that's ok.

Knightro63 commented 1 month ago

Hi @alexgrusu,

The worker is never deleted after it is created. Only the textures that are created for that instance is deleted like the FBO or the Metal texture.

The worker creates an instance with the dll of dylib files for dart ffi, deleting this is unnecessary because removing this would not be beneficial if you have to call it again later.

Hope this answers your question

alexgrusu commented 1 month ago

We do have a scenario where this could happen. For example, we could navigate to a screen, call setup for flutter angle, and perform an internal validation that triggers the navigation to a different context. This last one triggers the dispose call. It could happen to call dispose on the worker before it is assigned. Mainly this is the scenario that triggers what I described above. We have a different solution for this case, but it might happen to others. Feel free to close the issue if you consider this not important.

Knightro63 commented 1 month ago

Hi @alexgrusu,

Thanks for the information. I will keep it open and update this repo at some point to address this issue.