# Ableton crash when deleting WebView2 Window

**URL:** <https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964>\
**Category:** Windows\
**Created:** [June 27, 2022, 12:55pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964 "2022-06-27T12:55:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gm1](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gm1](https://forum.juce.com/u/gm1)\
**Post date:** [June 27, 2022, 12:55pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/1 "2022-06-27T12:55:43Z")

</div>

I have a plugin that loads a [WebView2](https://docs.juce.com/master/classWindowsWebView2WebBrowserComponent.html) 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.”

```auto
    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](https://www.ableton.com/en/manual/arrangement-view/)”, but when in [“Session view”](https://www.ableton.com/en/manual/session-view/) it always closes without a crash

---

<div class="post-metadata">

**Author:** ![harold](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@harold](https://forum.juce.com/u/harold)\
**Post date:** [July 14, 2022, 2:05pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/2 "2022-07-14T14:05:48Z")

</div>

It seems to be related to [this thread](https://forum.juce.com/t/vst3-and-juce-hwndcomponent/51893) I created. Whenever the PluginEditor is destroyed, it automatically destroys all child `HWND`s 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](https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environment?view=webview2-1.0.1264.42#createcorewebview2controller) 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

---

<div class="post-metadata">

**Author:** ![gm1](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gm1](https://forum.juce.com/u/gm1)\
**Post date:** [July 24, 2022, 8:16pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/3 "2022-07-24T20:16:01Z")

</div>

I have not yet managed to resolve the issue but I created a [minimal reproducible example.](https://github.com/gianmarcohutter/webview_crash) It crashes Ableton (11) when in [arrangement view](https://www.ableton.com/en/manual/arrangement-view/) and when deleting the track with the plugin on. @reuk do you maybe have an idea how to fix this?

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [August 8, 2022, 12:43pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/4 "2022-08-08T12:43:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gm1](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gm1](https://forum.juce.com/u/gm1)\
**Post date:** [August 8, 2022, 1:42pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/5 "2022-08-08T13:42:56Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [August 8, 2022, 1:59pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/6 "2022-08-08T13:59:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gm1](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gm1](https://forum.juce.com/u/gm1)\
**Post date:** [August 8, 2022, 2:23pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/7 "2022-08-08T14:23:58Z")

</div>

btw i found that if you comment out the code in [removed()](https://github.com/juce-framework/JUCE/blob/61fd8827e17fb22190e260c2091c0460fbecfb05/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp#L1811) 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…

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [August 8, 2022, 5:18pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/8 "2022-08-08T17:18:38Z")

</div>

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:

```auto
 	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.

---

<div class="post-metadata">

**Author:** ![gm1](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gm1](https://forum.juce.com/u/gm1)\
**Post date:** [August 8, 2022, 9:10pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/9 "2022-08-08T21:10:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [August 9, 2022, 9:27am UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/10 "2022-08-09T09:27:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![peteatjuce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/peteatjuce/32/2347_2.png) [@peteatjuce](https://forum.juce.com/u/peteatjuce)\
**Post date:** [August 13, 2022, 7:32pm UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/11 "2022-08-13T19:32:14Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![gm1](https://avatars.discourse-cdn.com/v4/letter/g/7ab992/32.png) [@gm1](https://forum.juce.com/u/gm1)\
**Post date:** [August 17, 2022, 10:10am UTC](https://forum.juce.com/t/ableton-crash-when-deleting-webview2-window/51964/12 "2022-08-17T10:10:43Z")

</div>

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 🙂
