Skip to content

Conversation

@tomoyanonymous
Copy link

@tomoyanonymous tomoyanonymous commented Dec 29, 2025

(edit: I read the RustAudio policy disallow the PR with AI, so I'm gonna edit this issue after I fully understand what I changed...)
This was discussed on Dicord before, that the open_parented example crashes only on macOS build.
I also found that some examples in nih-plug crashes similarly because of null pointer dereference.

I finally found these issues are a bit different things but could fixed with the help of AI... I am not professional of low-level window system and obj-C api of macOS, so it could be too much modification.

I will attach the summary of the modification from the conversation with ChatGPT.


What was fixed

macOS parented windows: ensured WindowInner stores the parent ns_window, so raw_window_handle() returns a valid window for child views (avoids null window handles that crashed softbuffer) — see src/macos/window.rs.
Metal surface creation: made the custom NSView layer-backed with a CAMetalLayer and keep it in sync on scale/resize, so wgpu’s Metal backend no longer panics on a nil layer — see src/macos/view.rs.

Why it mattered

Child windows were handing a null ns_window to downstream libraries, leading to null-pointer panics when creating rendering surfaces.
The view wasn’t layer-backed, so get_metal_layer saw nil and wgpu’s Metal backend aborted.

How it was fixed

Extract the parent window from the parent’s RawWindowHandle and store it in the child WindowInner for parented windows.
Enable wantsLayer, attach a CAMetalLayer, set its contentsScale/frame at creation, and update them on backing-scale or size changes.

Suggested verification

Run the open_parented example on debug build; confirm no softbuffer null-pointer panic.
Run a nih-plug/examples/gain_gui_iced example on debug build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant