From 53c7da7e51c84ab06ddccc027ede02c760a3eb49 Mon Sep 17 00:00:00 2001 From: Prome Date: Sat, 6 May 2023 10:49:25 +0800 Subject: [PATCH] fix buffer lock --- windows/webview_cef_plugin.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; }));