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.
This commit is contained in:
Jason Simmons
2019-07-18 15:54:21 -07:00
committed by GitHub
parent 470b204e42
commit 2f63de4797

View File

@@ -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