fix(macos): guard WebView async callback against use-after-free (macOS 26.5 crash/hang)#11052
Merged
Merged
Conversation
On macOS 26.5+ the wxWebView created in WebView::CreateWebView can be destroyed before the CallAfter() callback that registers the "wx" script message handler fires. The callback captured the raw webView pointer and called AddScriptMessageHandler() on it unconditionally, dereferencing a dangling pointer. On Apple Silicon this trips pointer authentication and crashes (EXC_BAD_ACCESS / PAC failure); elsewhere it shows up as a long startup hang with steadily growing memory use. Guard the async callback by checking g_webviews (the list of live views) before touching the webView, and also remove a view from g_delay_webviews in ~WebViewRef so a pending flush never reaches an already-destroyed view. Fixes bambulab#11004 Fixes bambulab#10968
Contributor
Author
|
Note on the failing This PR only touches Assimp's vendored It is fixed by #11051 ( |
BenJule
added a commit
to BenJule/BambuStudio
that referenced
this pull request
Jun 6, 2026
…F NULL-deref) (#490) Backports my two upstream crash fixes into the fork via develop. - **WebView use-after-free** (macOS 26.5+ PAC crash / hang) — upstream bambulab#11052, bambulab bambulab#11004/bambulab#10968 - **load_object_volume NULL-deref** (MakerWorld 3MF crash) — upstream bambulab#11053, bambulab bambulab#11016/bambulab#11037 Both are small defensive guards, verified upstream. WebView.cpp +14, 3DScene.cpp +9. Closes #489
Collaborator
|
thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS 26.5 / 26.5.1, BambuStudio either hangs for a long time on startup (#10968) or crashes within ~20 s of launch (#11004), with steadily growing memory use in both cases. The crash is an Apple-Silicon pointer-authentication failure:
Likely cause
WebView::CreateWebViewregisters the"wx"script message handler from aCallAfter()callback. The callback captures the rawwebViewpointer and callsAddScriptMessageHandler()on it.The stack (a
CreateWebViewlambda invoked fromwxAsyncMethodCallEventFunctor::Execute, failing with a PAC error on a corrupted pointer) is consistent with the WebKit view being torn down before this async callback runs, so the callback would dereference a freedwxWebView*(use-after-free). I am inferring the use-after-free from the stack and the PAC failure — I have not confirmed it with a heap / ASan trace — but the captured raw pointer makes it possible and it is the most likely explanation. On Apple Silicon a corrupted pointer trips pointer authentication → hard crash; elsewhere the same path surfaces as the long startup hang.The same hazard applies to
g_delay_webviews, which holds raw pointers that are never cleared when a view is destroyed.Fix
CallAfterlambda, checkg_webviews(the list of live views) and bail out ifwebViewhas already been destroyed.~WebViewRef, also remove the view fromg_delay_webviews, so a later flush of the delayed list can never touch a freed view.Small, self-contained change: no effect on Windows (the block runs synchronously there) and no functional change on the healthy path. The guards are defensive and correct regardless of whether the use-after-free is the exact mechanism.
Fixes #11004
Fixes #10968