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.
This was discussed on Dicord before, that the
open_parentedexample 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_windowfield was set toNone.This caused issues when external libraries called
raw_window_handle().raw_window_handle()would return null for thens_windowfield.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 returnednilbecause the view'swindowproperty is not immediately updated afteraddSubviewis called—it only gets set after theviewWillMoveToWindoworviewDidMoveToWindowcallbacks are invoked.So
open_parented()was modified to extract the parent window from the parent'sRawWindowHandleand store it in the child'sWindowInner.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
NSViewcreated by baseview was not layer-backed. When wgpu's Metal backend tried to obtain the view's layer to create a Metal surface, it receivednil.create_view()inview.rswas modified to make views layer-backed and attach aCAMetalLayer.set_frame_sizehook 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.