diff --git a/windows/webview_cef_plugin.cpp b/windows/webview_cef_plugin.cpp index a8faf99..1c26f96 100644 --- a/windows/webview_cef_plugin.cpp +++ b/windows/webview_cef_plugin.cpp @@ -26,12 +26,12 @@ namespace webview_cef { std::unique_ptr backing_pixel_buffer; std::mutex buffer_mutex_; std::unique_ptr m_texture = std::make_unique(flutter::PixelBufferTexture([](size_t width, size_t height) -> const FlutterDesktopPixelBuffer* { + buffer_mutex_.lock(); auto buffer = pixel_buffer.get(); // Only lock the mutex if the buffer is not null // (to ensure the release callback gets called) - if (buffer) { - // Gets unlocked in the FlutterDesktopPixelBuffer's release callback. - buffer_mutex_.lock(); + if (!buffer) { + buffer_mutex_.unlock(); } return buffer; }));