Skip to content

Conversation

@icculus
Copy link
Collaborator

@icculus icculus commented Apr 18, 2024

This allows apps to destroy the window and renderer in either order, but makes sure that the renderer can properly clean up its resources while OpenGL contexts and libraries are still loaded, etc.

If the window is destroyed first, the renderer is (mostly) destroyed but its pointer remains valid. Attempts to use the renderer will return an error, but it can still be explicitly destroyed, at which time the struct is free'd.

If the renderer is destroyed first, everything works as before, and a new renderer can still be created on the existing window.

This also moves memory management of the SDL_Renderer struct itself out of the backends and to the higher level, which was necessary for this, but also turned out to be a nice code cleanup.

Fixes #9540.

icculus added 2 commits April 18, 2024 14:12
Previously, each backend would allocate and free the renderer struct. Now
the higher level does it, so the backends only manage their private resources.

This removes some boilerplate and avoids some potential accidents.
This allows apps to destroy the window and renderer in either order, but
makes sure that the renderer can properly clean up its resources while OpenGL
contexts and libraries are still loaded, etc.

If the window is destroyed first, the renderer is (mostly) destroyed but its
pointer remains valid. Attempts to use the renderer will return an error,
but it can still be explicitly destroyed, at which time the struct is free'd.

If the renderer is destroyed first, everything works as before, and a new
renderer can still be created on the existing window.

Fixes libsdl-org#9540.
@icculus icculus force-pushed the sdl3-render-and-window-destruction branch from 657c317 to 19b59fc Compare April 18, 2024 18:12
@icculus
Copy link
Collaborator Author

icculus commented Apr 18, 2024

CI is green, I'm merging this shortly unless I hear otherwise.

@icculus icculus merged commit cab3def into libsdl-org:main Apr 19, 2024
@icculus icculus deleted the sdl3-render-and-window-destruction branch April 19, 2024 04:26
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.

(SDL2) Does SDL_DestroyWindow destroy the window's associated SDL_Renderer, if one exists?

1 participant