vulkano
vulkano copied to clipboard
Surface creation blackholes the window parameter upon failure
Issue
Looking at the existing methods to create a surface, I've noticed the window parameter that is passed in as a sort of anchor to ensure the vulkan khr surface lives as long as the window. The problem this is if surface creation fails, then the window object is dropped. This can cause issues if you want to try to use a vulkan backend and fallback to OpenGL as then your window is just gone with the case of winit.
I might be missing something here in your issue, but the as you said:
the window parameter that is passed in as a sort of anchor to ensure the vulkan khr surface lives as long as the window
is exactly true; however, you should be passing the window as a reference. In your case where surface creation fails, you should still have the window available, as you only pass a reference. I don't think the surface creation should result in a panic anywhere that would prevent you from continuing other means.
Taking a look at vulkano_win, that seems to require SafeBorrow on its input.
Seeing from what you said, I probably shouldn't be making the surface own the window.
Based on what you said it may be worth noting the surface creation methods should borrow the window object passed to it?
I don't think this can be solved with a borrow, but wrapping the window in an Arc will do it.
The above ^ has been implemented in #2204.