From 90e72dbd986d927af1cbc62891cde1255c29ad72 Mon Sep 17 00:00:00 2001 From: attila Date: Fri, 17 Jan 2025 16:12:51 +0100 Subject: [PATCH] Windows: Fix faulty mechanism for creating multiple WebView2 instances serially Prior to this commit it was possible for the WebBrowserComponent implementation on Windows to end up in an infinite loop if multiple WebBrowserComponent objects were being created at the same time. When an instance was already being created, the createWebView() call for the second would place it in a queue and return without initiating its creation. When the first WebView finishes creation, it calls the handleAsyncUpdate() function of the second. However handleAsyncUdpate() would see that the webViewBeingCreated helper variable was already true and not call createWebView(), hence the second WebView would never be created. If, in the meantime, the scriptsWaitingForExecution variable wasn't empty, handleAsyncUpdate() would endlessly call triggerAsyncUpdate(). --- .../native/juce_WebBrowserComponent_windows.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp b/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp index 0ff48a8a21..ddd734329b 100644 --- a/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp +++ b/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp @@ -686,7 +686,6 @@ public: if (webView == nullptr) { scriptsWaitingForExecution.push_back ({ script, std::move (callbackIn) }); - triggerAsyncUpdate(); return; } @@ -1059,6 +1058,7 @@ private: { if (weakThis != nullptr) { + weakThis->triggerAsyncUpdate(); webView2ConstructionHelper.webView2BeingCreated = nullptr; if (controller != nullptr) @@ -1156,15 +1156,9 @@ private: //============================================================================== void handleAsyncUpdate() override { - if (webView == nullptr && ! webViewBeingCreated) + if (webView == nullptr) { - webViewBeingCreated = true; createWebView(); - } - - if (webView == nullptr && ! scriptsWaitingForExecution.empty()) - { - triggerAsyncUpdate(); return; } @@ -1206,7 +1200,6 @@ private: WebViewHandle webViewHandle; ComSmartPtr webViewController; ComSmartPtr webView; - bool webViewBeingCreated = false; EventRegistrationToken navigationStartingToken { 0 }, newWindowRequestedToken { 0 },