Skip to content

Conversation

@999pingGG
Copy link
Contributor

@999pingGG 999pingGG commented Dec 19, 2025

Description

I want to put this up for review since this doesn't look very clean to me and I'm not sure about the best way to do it (for example, the pointer to vkCreateAndroidSurfaceKHR() is retrieved every time it's used), but the problem is (mostly) fixed.

I've found the cause of failure when switching apps with SDL GPU. Not only the swapchain needs to be recreated, the surface must be recreated, too. I'm still getting an error which I haven't managed to fix: vkCreateSwapchainKHR VK_ERROR_NATIVE_WINDOW_IN_USE_KHR. But at least now we can ignore it and rendering will continue the next frame after resuming the app, fixing the regression made in 1260c10.

Usage notes: In order to avoid another error, the app should stop rendering (stop calling SDL_WaitAndAcquireGPUSwapchainTexture()) when the event SDL_EVENT_WINDOW_FOCUS_LOST SDL_EVENT_DID_ENTER_BACKGROUND is received, and resume rendering on SDL_EVENT_WINDOW_FOCUS_GAINED SDL_EVENT_DID_ENTER_FOREGROUND.

@999pingGG
Copy link
Contributor Author

My latest commit fixes vkCreateSwapchainKHR VK_ERROR_NATIVE_WINDOW_IN_USE_KHR and now it's all error-free.

@slouken slouken added this to the 3.4.0 milestone Dec 19, 2025
@slouken
Copy link
Collaborator

slouken commented Dec 19, 2025

Do my latest two commits still work? Do you see any other issues with them?

@999pingGG
Copy link
Contributor Author

Your latest commit doesn't work because initially I had it like that, but then VULKAN_INTERNAL_CreateSwapchain() needs to know if the surface has been recreated (app switch) or it's just the swapchain (device rotated or view resized), because if it's a surface recreation then it needs to not pass the old swapchain, otherwise we get VK_ERROR_NATIVE_WINDOW_IN_USE_KHR. That's also why I surrounded it in the Android #ifdef, for other platforms it doesn't seem very correct. Or is there a better way to handle this?

@slouken
Copy link
Collaborator

slouken commented Dec 19, 2025

Your latest commit doesn't work because initially I had it like that, but then VULKAN_INTERNAL_CreateSwapchain() needs to know if the surface has been recreated (app switch) or it's just the swapchain (device rotated or view resized), because if it's a surface recreation then it needs to not pass the old swapchain, otherwise we get VK_ERROR_NATIVE_WINDOW_IN_USE_KHR. That's also why I surrounded it in the Android #ifdef, for other platforms it doesn't seem very correct. Or is there a better way to handle this?

Ah, okay, that makes sense. Can you revert my latest commit and double check that?

@slouken
Copy link
Collaborator

slouken commented Dec 19, 2025

Maybe also add a code comment explaining why updating that variable is delayed, so someone doesn't try to "clean it up" later?

@999pingGG
Copy link
Contributor Author

Unless I've missed something, this should be all good. BTW, this is my first time doing a reviewed PR like this!

@slouken slouken merged commit 190b902 into libsdl-org:main Dec 19, 2025
43 checks passed
@slouken
Copy link
Collaborator

slouken commented Dec 19, 2025

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants