From 2f63de47972ae440bf5fe9bf356988c7391a2470 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 18 Jul 2019 15:54:21 -0700 Subject: [PATCH] Fix reentrancy handling in SingleFrameCodec (flutter/engine#9931) After the frame is decoded SingleFrameCodec will invoke pending callbacks from calls to getNextFrame. The callbacks could result in more calls to getNextFrame. Those calls should receive the frame instead of being added to the pending list. --- engine/src/flutter/lib/ui/painting/single_frame_codec.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/lib/ui/painting/single_frame_codec.cc b/engine/src/flutter/lib/ui/painting/single_frame_codec.cc index b992a95e52..d799e31c36 100644 --- a/engine/src/flutter/lib/ui/painting/single_frame_codec.cc +++ b/engine/src/flutter/lib/ui/painting/single_frame_codec.cc @@ -83,13 +83,16 @@ Dart_Handle SingleFrameCodec::getNextFrame(Dart_Handle callback_handle) { std::move(canvas_image), 0 /* duration */); } + // The cached frame is now available and should be returned to any future + // callers. + codec->status_ = Status::kComplete; + + // Invoke any callbacks that were provided before the frame was decoded. Dart_Handle frame = tonic::ToDart(codec->cached_frame_); for (const DartPersistentValue& callback : codec->pending_callbacks_) { tonic::DartInvoke(callback.value(), {frame}); } codec->pending_callbacks_.clear(); - - codec->status_ = Status::kComplete; }); // The encoded data is no longer needed now that it has been handed off