vulkano icon indicating copy to clipboard operation
vulkano copied to clipboard

Surface creation blackholes the window parameter upon failure

Open i509VCB opened this issue 4 years ago • 2 comments

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.

i509VCB avatar Jun 20 '21 22:06 i509VCB

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.

AustinJ235 avatar Jun 21 '21 04:06 AustinJ235

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?

i509VCB avatar Jun 21 '21 04:06 i509VCB

I don't think this can be solved with a borrow, but wrapping the window in an Arc will do it.

Rua avatar Dec 28 '22 19:12 Rua

The above ^ has been implemented in #2204.

marc0246 avatar Jul 07 '23 04:07 marc0246