You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Currently, the ns_window field on WindowInner is only set in the non-parented case, when baseview is responsible for creating and managing the NSWindow, and this is very much intentional:
/// Only set if we created the parent window, i.e. we are running in
/// parentless mode
In the parented case, the host is responsible for managing the NSWindow, and baseview should not be performing operations like resizing or closing it. This PR will cause baseview to incorrectly resize the parent NSWindow in Window::resize:
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
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
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.