Skip to content

Conversation

@tomoyanonymous
Copy link

@tomoyanonymous tomoyanonymous commented Dec 29, 2025

This was discussed on Dicord before, that the open_parented example crashes only on macOS build.
I also found that some gui examples in nih-plug crashes similarly because of null pointer dereference.

I finally found these issues are different problem but both are now fixed.

The problem 1:The open_parented example was crashing with a null pointer dereference when libraries like softbuffer attempted to create rendering surfaces. The crash occurred because child windows were not properly storing a reference to their parent window.

When creating a parented (child) window, the WindowInner::ns_window field was set to None.
This caused issues when external libraries called raw_window_handle().
raw_window_handle() would return null for the ns_window field.
Libraries like softbuffer would receive a null window handle and crash when trying to create rendering contexts
Attempting to get the window from the view via [ns_view window] also returned nil because the view's window property is not immediately updated after addSubview is called—it only gets set after the viewWillMoveToWindow or viewDidMoveToWindow callbacks are invoked.

So open_parented() was modified to extract the parent window from the parent's RawWindowHandle and store it in the child's WindowInner.

The Problem 2: Applications using wgpu or other Metal-based rendering libraries were crashing when attempting to create Metal surfaces. The crash occurred in wgpu's Metal backend with the null pointer dereference.

The custom NSView created by baseview was not layer-backed. When wgpu's Metal backend tried to obtain the view's layer to create a Metal surface, it received nil.

create_view() in view.rs was modified to make views layer-backed and attach a CAMetalLayer.
set_frame_size hook is not necessary for fixing crash but it will be needed for window resizing.

to test:
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