diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index ee480a68ba..094746b26d 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -348,9 +348,22 @@ bool DartIsolate::PrepareForRunningFromKernel( return false; } - child_isolate_preparer_ = [mapping](DartIsolate* isolate) { - return isolate->PrepareForRunningFromKernel(mapping); - }; + // Child isolate shares root isolate embedder_isolate (lines 691 and 693 + // below). Re-initializing child_isolate_preparer_ lambda while it is being + // executed leads to crashes. + if (child_isolate_preparer_ == nullptr) { + child_isolate_preparer_ = [buffers = + kernel_buffers_](DartIsolate* isolate) { + for (unsigned long i = 0; i < buffers.size(); i++) { + bool last_piece = i + 1 == buffers.size(); + const std::shared_ptr& buffer = buffers.at(i); + if (!isolate->PrepareForRunningFromKernel(buffer, last_piece)) { + return false; + } + } + return true; + }; + } phase_ = Phase::Ready; return true; } diff --git a/engine/src/flutter/runtime/dart_isolate.h b/engine/src/flutter/runtime/dart_isolate.h index 86fce82aaf..d79cc6c6b6 100644 --- a/engine/src/flutter/runtime/dart_isolate.h +++ b/engine/src/flutter/runtime/dart_isolate.h @@ -114,7 +114,7 @@ class DartIsolate : public UIDartState { const fml::RefPtr shared_snapshot_; std::vector> kernel_buffers_; std::vector> shutdown_callbacks_; - ChildIsolatePreparer child_isolate_preparer_; + ChildIsolatePreparer child_isolate_preparer_ = nullptr; FML_WARN_UNUSED_RESULT bool Initialize(Dart_Isolate isolate, bool is_root_isolate);