flutter-tizen / engine

The Flutter engine
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
6 stars 19 forks source link

Fix FlutterEngineOnVsync being called after engine shutdown #355

Closed swift-kim closed 2 years ago

swift-kim commented 2 years ago

Potentially fixes https://github.com/flutter-tizen/flutter-tizen/issues/232.

This change is just a partial revert of https://github.com/flutter-tizen/engine/pull/317. In the PR, I changed tdm_client_ from a plain pointer to a shared_ptr which is shared between the platform thread and the vblank thread, but it turned out that it results in a synchronization issue in https://github.com/flutter-tizen/flutter-tizen/issues/232 for some unknown reason. The main reason I changed it into a shared_ptr was that it seemed not safe to call OnEngineStop on a plain pointer because the object pointed by the pointer was being destroyed on thread exit. However, in reality, OnEngineStop is guaranteed to be called before a kMessageQuit message is sent and thus no segmentation fault should occur.

I also considered removing the vblank thread itself but thought it would not be very efficient since tdm_client_handle_events is a blocking call and blocks the UI thread.

swift-kim commented 2 years ago

I changed tdm_client_ back to a share_ptr and just replaced reset() with OnEngineStop() according to @bbrto21's suggestion. The problem was that the instance was not destroyed when reset() was called and thus engine_ = nullptr; was not called as I expected. Thank you!