From ae23783f63835c1abd9988806e02fbaa00022cc5 Mon Sep 17 00:00:00 2001 From: attila Date: Sat, 13 Jul 2024 19:56:30 +0200 Subject: [PATCH] Windows: Fix rare crash when creating and destroying WebBrowserComponent instances --- .../native/juce_WebBrowserComponent_windows.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp b/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp index 6e6c3853ed18..b7752a9ff06d 100644 --- a/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp +++ b/modules/juce_gui_extra/native/juce_WebBrowserComponent_windows.cpp @@ -519,6 +519,12 @@ class WebBrowserComponent::Impl::Platform::WebView2 final : public WebBrowserCom ~WebView2() override { + if (webView2ConstructionHelper.webView2BeingCreated == this) + webView2ConstructionHelper.webView2BeingCreated = nullptr; + + webView2ConstructionHelper.viewsWaitingForCreation.erase (this); + + cancelPendingUpdate(); removeEventHandlers(); closeWebView(); } @@ -1022,8 +1028,6 @@ class WebBrowserComponent::Impl::Platform::WebView2 final : public WebBrowserCom webView2ConstructionHelper.viewsWaitingForCreation.erase (this); webView2ConstructionHelper.webView2BeingCreated = this; - WeakReference weakThis (this); - webViewHandle.environment->CreateCoreWebView2Controller ((HWND) peer->getNativeHandle(), Callback ( [weakThis = WeakReference { this }] (HRESULT, ICoreWebView2Controller* controller) -> HRESULT