Ableton crash when deleting WebView2 Window

I have a plugin that loads a WebView2 and all works well but if I delete the channel with the plugin in Ableton* while the Window is open then it crashes in a way that I have no idea how to fix.
The debugger stops in “juce_win32_Windowing.cpp” at line 2611 when calling “DestroyWindow(hwnd)”
with the message:
“Exception thrown at 0x0000000142EBA720 in Ableton Live 11 Suite.exe: 0xC0000005: Access violation reading location 0x0000000000000000.”

    static void* destroyWindowCallback (void* handle)
    {
        auto hwnd = reinterpret_cast<HWND> (handle);

        if (IsWindow (hwnd))
        {
            RevokeDragDrop (hwnd);

            // NB: we need to do this before DestroyWindow() as child HWNDs will be invalid after
            EnumChildWindows (hwnd, revokeChildDragDropCallback, 0);

            DestroyWindow (hwnd);
        }

        return nullptr;
}

This all happens before the destructors of my WebView get hit. So I’m absolutely lost as in what I can do to prevent this?

As far as I know it’s not ok to delete from another thread than where the window was created but I have no Idea of where these things get created and what I can do about it, so any help is greatly appreciated!

*What is super weird is that it sometimes it’s no problem (so probably some race condition?) and that it only happens if it’s in “Arrangement view”, but when in “Session view” it always closes without a crash

It seems to be related to this thread I created. Whenever the PluginEditor is destroyed, it automatically destroys all child HWNDs with it, before entering the destructor. This is due to the behavior of the Win32 DestroyWindow function.

Looking at the juce_win32_WebBrowserComponent.cpp on line 657 the CreateCoreWebView2Controller function is called. The documentation of that function says the first argument is the parentWindow the WebView2 should add itself to. So the WebView2 is a HWND child of the PluginEditor HWND, which is then destroyed by DestroyWindow while the JuceVST3Editor invokes removeFromDesktop() on the PluginEditor.

I’ve proposed two solution in my thread for redisplaying the juce::HWNDComponent after the plugineditor is destroyed, and I think those solutions might fix your issue too

I have not yet managed to resolve the issue but I created a minimal reproducible example. It crashes Ableton (11) when in arrangement view and when deleting the track with the plugin on. @reuk do you maybe have an idea how to fix this?

1 Like

I just tried to reproduce the crash using your example, but I wasn’t able to trigger the problem.

I tried openeing the plugin’s editor, then switching between arrangement/session view and deleting the track containing the plugin. I didn’t see any crashes or assertions in either case.

I’m testing with Windows 11, Ableton Live 11.2b7, and JUCE’s develop branch. Please can you confirm that you can reproduce the issue with the latest develop branch? If the issue is still present, then please also provide your Live and Windows versions.

thanks alot for getting back to me! I previously used the Main branch (lastest version) but just tested with the develop as well and the issue persists. I’m on Windows 10, Ableton Live 11.0.12 (also happens on my test machine with Win10, Ableton Live Trial 11.0.6). Note that the crash only happens when the Plugin editor is visible when deleting the track in session view.
Even found some other Juce plugins out in the wild that crash the same way on my machine (they use WebView2 as well)

Thanks, I can repro the issue in Live Lite 11.0.12 when deleting the track. I’ll investigate further.

1 Like

btw i found that if you comment out the code in removed() then the deleting of the track works without a crash but to be honest I have no idea why that code is needed so I assume removing it just causes issues somewhere else…

I’ve debugged this a bit, and at the moment I’m not sure exactly what is causing the problem. The actual crash happens quite a long way inside the DestroyWindow call:

 	Ableton Live 11 Lite.exe!0000000142eba724()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db03()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014204db67()	Unknown
 	Ableton Live 11 Lite.exe!000000014209dfb9()	Unknown
 	Ableton Live 11 Lite.exe!000000014209e30a()	Unknown
 	Ableton Live 11 Lite.exe!000000014205301f()	Unknown
 	Ableton Live 11 Lite.exe!00000001420b1027()	Unknown
 	Ableton Live 11 Lite.exe!00000001420b147b()	Unknown
 	Ableton Live 11 Lite.exe!00000001420b198e()	Unknown
 	Ableton Live 11 Lite.exe!00000001420aec2f()	Unknown
	user32.dll!UserCallWinProcCheckWow()	Unknown
 	user32.dll!DispatchClientMessage()	Unknown
 	user32.dll!__fnDWORD()	Unknown
 	ntdll.dll!KiUserCallbackDispatcherContinue()	Unknown
 	win32u.dll!NtUserShowWindow()	Unknown
 	apphelp.dll!SrHook_ShowWindow()	Unknown
 	EmbeddedBrowserWebView.dll!00007fffe9956597()	Unknown
 	EmbeddedBrowserWebView.dll!00007fffe994ae42()	Unknown
 	EmbeddedBrowserWebView.dll!00007fffe994a75c()	Unknown
 	EmbeddedBrowserWebView.dll!00007fffe9ba9251()	Unknown
 	EmbeddedBrowserWebView.dll!00007fffe9ba9318()	Unknown
 	EmbeddedBrowserWebView.dll!00007fffe9ba8fff()	Unknown
 	user32.dll!UserCallWinProcCheckWow()	Unknown
 	user32.dll!DispatchClientMessage()	Unknown
 	user32.dll!__fnDWORD()	Unknown
 	ntdll.dll!KiUserCallbackDispatcherContinue()	Unknown
 	win32u.dll!NtUserDestroyWindow()	Unknown
 	webview_crash.vst3!juce::HWNDComponentPeer::destroyWindowCallback(void * handle) Line 2629	C++
 	webview_crash.vst3!juce::HWNDComponentPeer::callFunctionIfNotLocked(void *(*)(void *) callback, void * userData) Line 3879	C++
 	webview_crash.vst3!juce::HWNDComponentPeer::~HWNDComponentPeer() Line 1678	C++
 	webview_crash.vst3!juce::HWNDComponentPeer::`scalar deleting destructor'(unsigned int)	C++
 	webview_crash.vst3!juce::Component::removeFromDesktop() Line 790	C++
 	webview_crash.vst3!juce::JuceVST3EditController::JuceVST3Editor::removed() Line 1835	C++
 	Ableton Live 11 Lite.exe!0000000140f859a1()	Unknown
 	// truncated

As you can see, Live calls removed on the editor to tell it to detach from the host window.
DestroyWindow will recursively destroy the children of the provided window; we see the system passing a message to the embedded browser window, presumably notifying it that it is about to be destroyed. Then, the browser window sends a message which is received by Live. The actual crash happens while Live is processing this message.

Unfortunately I can’t easily debug this much further. However, given that the crash happens inside Live, and that the crash doesn’t seem to be present in the latest version of Live, I suspect that this is a bug in older versions of Live.

Do you think not calling what is in removed will cause bigger issues? I guess it’s a terrible solution but at least it does not crash (my version of) Live

The main problem would be that the editor component itself wouldn’t be destroyed when closing the editor window, so any resources used by the editor wouldn’t be cleaned up properly. This would be quite wasteful.

There might be other problems too, but without testing it I’d just be guessing. The VST3 spec says that the editor window should be removed from the host’s window inside removed(), so I think JUCE should continue to do that.

Hi! Just trying this as requested by @gm1 - sorry it has taken a few days to get around to, but I’m on holiday right now :slight_smile:

I’ve (just now) used the Debug build of Wotja 22 Pro VST3, using the very latest Ableton Live Suite 11 (installed fresh today on Windows 11), and didn’t have a crash when deleting the Track that contained the Wotja plug-in (even when playing audio through Wotja).

@gm1 if there is a specific test you would like me to try with Wotja, do please let me know here, and I’ll try it for you in a couple of days.

Best wishes, Pete

Thanks alot @peteatjuce the issue apparently only happens with Live version around 11.0.12 but with the most recent Live version they have fixed the crash :slight_smile:

1 Like