Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jason-simmons
Copy link
Member

The DartPersistentValue used to hold the image callback is tied to a
Dart isolate. Destructing the DartPersistentValue requires entering
the isolate and must be done on the UI thread.

Fixes flutter/flutter#29379

… on the UI thread

The DartPersistentValue used to hold the image callback is tied to a
Dart isolate.  Destructing the DartPersistentValue requires entering
the isolate and must be done on the UI thread.

Fixes flutter/flutter#29379
auto* raw_dart_image = tonic::ToDart(std::move(dart_image));

// All done!
tonic::DartInvoke(image_callback->Get(), {raw_dart_image});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect that the std::unique_ptr to be destructed here after that image_callback is no longer used, which means destruction in the ui thread. Is it not the case? @chinmaygarde

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old implementation, the std::unique_ptr was being captured into a ref counted lambda by MakeCopyable.

The MakeCopyable lambda was then being passed through the GPU thread to the UI thread. Either the GPU thread or the UI thread could drop the last reference to the lambda. If the GPU thread destroyed the lambda, then the captured image_callback would be destructed on the GPU thread, causing a failure.

@jason-simmons jason-simmons merged commit 6c948ba into flutter:master Mar 28, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 28, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 29, 2019
RBogie pushed a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
… on the UI thread (flutter#8182)

The DartPersistentValue used to hold the image callback is tied to a
Dart isolate.  Destructing the DartPersistentValue requires entering
the isolate and must be done on the UI thread.

Fixes flutter/flutter#29379
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
@eggfly
Copy link
Member

eggfly commented Nov 19, 2020

The DartPersistentValue used to hold the image callback is tied to a
Dart isolate. Destructing the DartPersistentValue requires entering
the isolate and must be done on the UI thread.

Fixes flutter/flutter#29379

I've faced the same problem related to this vm shutdown:

"Unable to Enter Isolate : Multiple mutators entering an isolate / Dart VM is shutting down" in dart_api_impl.cc from Dart_EnterIsolate() function.

And I digged some code related to dart_persistent_value.cc, dart_isolate_scope.cc, dart_api_impl.cc, but still don't know why "Destructing the DartPersistentValue requires entering the isolate and must be done on the UI thread", May I ask you why UI Thread?

@eggfly
Copy link
Member

eggfly commented Nov 19, 2020

If I created DartPersistentValue's unique_ptr in io task runner:
std::make_unique<tonic::DartPersistentValue>(tonic::DartPersistentValue* image_callback = dart_state, raw_image_callback) // in io runner

Then should I manually make sure that DartPersistentValue's unique_ptr is destructed in io thread or also ui thread? And not using the ref count logic inside MakeCopyable lambda.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VM crashes while loading and resizing images in Flutter Android app (Multiple mutators entering an isolate / Dart VM is shutting down)

5 participants