Fixed window crashes on macOS#219
Conversation
5dc5a10 to
d73e0b9
Compare
|
Currently, the Lines 61 to 62 in 237d323 In the parented case, the host is responsible for managing the Lines 330 to 333 in 237d323 and to incorrectly close it in Lines 92 to 95 in 237d323 |
This should not occur with the latest version of softbuffer, as it uses |
|
We had a discussion on discord some time ago regarding this PR. To quote myself and replies:
@micahrj had a look and confirmed that the change in this PR is not in a good state:
and it was confirmed through further discussion. You can read here. So I believe we can close this PR. |
I was gonna come to the same conclusion but you beat me to it 😄 I completely agree with @micahrj here, overriding the The issue of the I could not find a way to easily reproduce the Metal Layer issue (the nih_plug example relies on a completely outdated version of baseview), but it seems pretty crazy to me to add a So for those reasons, I will close this PR, and address those two issues separately. |
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.