Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

MacOS wgpu-rs with sdl2 raw-window-handle Crashes #187

Closed
Kethku opened this issue Mar 3, 2020 · 11 comments
Closed

MacOS wgpu-rs with sdl2 raw-window-handle Crashes #187

Kethku opened this issue Mar 3, 2020 · 11 comments
Labels
bug Something isn't working

Comments

@Kethku
Copy link

Kethku commented Mar 3, 2020

I'm considering wgpu-rs as a renderer platform for an editor gui I am working on, but in some basic tests I got reports of a crash on MacOS. I don't myself have a mac to test it on locally, but it seems like something about the raw-window-handle isn't working properly.

The test repo is here: https://github.com/Kethku/sdl2-wgpu-test

This is the description of the error I got:
"I gave sdl2-wgpu-test on macOS a brief run. It seems what happens is that the SDL2 window that is created (which is a NSWindow) does either not have an actual NSView for wgpu to use, or it is the wrong type. The panic happens here: https://github.com/gfx-rs/gfx/blob/77c3e28331f8ab593e57425b47db344f0e9e8112/src/backend/metal/src/lib.rs#L366 and it is transmuting to cocoa::base::id. Interestingly, it should have a view, which is a SDLView, which in turn is a subclass of NSView (https://github.com/LuaDist/sdl/blob/e3fb85ea57742a3358ae8e20ecba83f8ef006d28/src/video/cocoa/SDL_cocoawindow.m#L574). So it might be that the transmute fails because it is a different class. "

@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

This test runs without difficulty on windows. I do not have any data if it runs on linux

@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

I suppose it is very possible that this issue should be raised in the upstream repo. If so I am happy to do so

@kvark
Copy link
Member

kvark commented Mar 3, 2020

Could you print out the RawWindowHandle being passed to wgpu/gfx?

@kvark kvark added the bug Something isn't working label Mar 3, 2020
@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

I cannot since I don't have a mac. However I looked up the sdl2 source and the ns_view is set to 0 https://github.com/Rust-SDL2/rust-sdl2/blob/master/src/sdl2/raw_window_handle.rs#L65

@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

And to prove it should be handled by gfx-hal or w/e the raw_window_handle folks say that windowing systems are not required to set it to an actual value: rust-windowing/raw-window-handle#14 (comment)

@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

I looked up where it is consumed and looks like wgpu's dependency requires the ns_view to have a value: https://github.com/gfx-rs/gfx/blob/77c3e28331f8ab593e57425b47db344f0e9e8112/src/backend/metal/src/lib.rs#L266

@kvark
Copy link
Member

kvark commented Mar 3, 2020

Looks like this was fixed by gfx-rs/wgpu#462. Could you try depending on the git version of latest wgpu master?

@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

Oh very cool. Yes I will try this

@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

Edit: nvm I was confused

@Kethku
Copy link
Author

Kethku commented Mar 3, 2020

This will require updated wgpu glyph in a branch. I will do this tonight and ask the person who encountered the error to test it. This looks very likely to fix the issue though so I will close it. Thanks for the help!

@Kethku Kethku closed this as completed Mar 3, 2020
@kvark
Copy link
Member

kvark commented Mar 3, 2020

One more reason for us to make a release... https://github.com/gfx-rs/wgpu-rs/milestone/1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants