-
Notifications
You must be signed in to change notification settings - Fork 6k
Introduce runtime check that it is root isolate that makes UI native calls. #18050
Conversation
…ates (flutter#6401)" This reverts commit 69ae569 as it doesn't work when root and secondary isolates run in the same isolate group.
Hi @jason-simmons , please let me know what you think about this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was attempting to find and validate that each check was necessary (and a couple were not) and realized that chasing all existing callback and adding the check is tedious and error prone. Instead of making it so the thread is checked in each and every single callback, why can't we just update DartLibraryNative::Register
to forego the registration if made on the wrong thread. That way, the callback should be faster as well.
lib/ui/text/paragraph.cc
Outdated
@@ -52,42 +52,52 @@ size_t Paragraph::GetAllocationSize() { | |||
} | |||
|
|||
double Paragraph::width() { | |||
UIDartState::ThrowIfUIOperationsProhited(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems redundant. Methods invocations on this C++ object should already go through FOR_EACH_BINDING
to DART_NATIVE_CALLBACK
which you have already guarded below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, true. Removed.
Foregoing of registration won't work because registration is not per isolate. Registration is per-library and in case of enabled isolate groups where isolates share library objects, affects all isolates in a group. So this change effectively makes secondary isolates register same native handlers, which is harmless but redundant(currently secondary isolate registers reduced number of native handlers breaking root isolate native handler lookups associated with library objects shared between two isolates). |
Thanks Chinmay. cc @mkustermann |
With upcoming '--enable-isolate-groups' Dart VM option, flutter engine won't be able to register different native call handlers for same library in isolates in the same isolate group. The reason is that library objects are shared between all isolates in the same isolate group.
Proposed solution introduces runtime check into native calls.