Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: Fix dangling pointers in _clean_up_swap_chain #79884

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

Dragoncraft89
Copy link
Contributor

@Dragoncraft89 Dragoncraft89 commented Jul 25, 2023

In _clean_up_swap_chain, the state was not fully reset to the empty state, leaving the render_pass pointer and the swapchainImageCount with their previous values.

This causes a double free when _clean_up_swap_chain has been called twice without recreating the state in between. With this patch, the second _clean_up_swap_chain effectively behaves as a no-op if there is nothing to free.

swapchainImageCount is reset to 0 in this patch, because while the previous change is enough to fix the crash, the vulkan context fails to be recreated if there are any image resources currently active. However, we just freed all resources, so it makes sense to reset the count.

Fixes #65391
Fixes #73922

Maybe fixes these #64766 #70837 #72080
However, I couldn't reproduce the latter crashes to begin with. @nathanfranke @henriquelalves @michael-nischt please check if this PR fixes your issue

@Dragoncraft89 Dragoncraft89 requested a review from a team as a code owner July 25, 2023 12:56
@YuriSizov YuriSizov added this to the 4.2 milestone Jul 25, 2023
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. For render_pass it looks like it never gets used without being initialized first (but setting to null is still a good idea).

For swapchainImageCount this also seems correct. A user on rocketchat noted that this caused issues with certain XR devices as well https://chat.godotengine.org/channel/xr?msg=REFux829ofRXrfn2f

@YuriSizov YuriSizov changed the title Fix dangling pointers in _clean_up_swap_chain Vulkan: Fix dangling pointers in _clean_up_swap_chain Jul 25, 2023
@YuriSizov YuriSizov merged commit 202e4b2 into godotengine:master Jul 25, 2023
13 checks passed
@YuriSizov
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants