33// found in the LICENSE file.
44
55#include " flutter/lib/ui/painting/picture.h"
6+
67#include < memory>
78
89#include " flutter/fml/make_copyable.h"
@@ -81,6 +82,8 @@ Dart_Handle Picture::RasterizeToImage(sk_sp<SkPicture> picture,
8182 }
8283
8384 auto * dart_state = UIDartState::Current ();
85+ auto image_callback = std::make_shared<tonic::DartPersistentValue>(
86+ dart_state, raw_image_callback);
8487 auto unref_queue = dart_state->GetSkiaUnrefQueue ();
8588 auto ui_task_runner = dart_state->GetTaskRunners ().GetUITaskRunner ();
8689 auto raster_task_runner = dart_state->GetTaskRunners ().GetRasterTaskRunner ();
@@ -93,11 +96,8 @@ Dart_Handle Picture::RasterizeToImage(sk_sp<SkPicture> picture,
9396
9497 auto picture_bounds = SkISize::Make (width, height);
9598
96- auto ui_task = fml::MakeCopyable ([raw_image_callback, dart_state,
97- unref_queue](
99+ auto ui_task = fml::MakeCopyable ([image_callback, unref_queue](
98100 sk_sp<SkImage> raster_image) mutable {
99- auto image_callback = std::make_unique<tonic::DartPersistentValue>(
100- dart_state, raw_image_callback);
101101 auto dart_state = image_callback->dart_state ().lock ();
102102 if (!dart_state) {
103103 // The root isolate could have died in the meantime.
@@ -118,7 +118,8 @@ Dart_Handle Picture::RasterizeToImage(sk_sp<SkPicture> picture,
118118 tonic::DartInvoke (image_callback->Get (), {raw_dart_image});
119119
120120 // image_callback is associated with the Dart isolate and must be deleted
121- // on the UI thread. It gets deleted when it goes out of scope here.
121+ // on the UI thread.
122+ image_callback.reset ();
122123 });
123124
124125 // Kick things off on the raster rask runner.
0 commit comments