Commit 1af7c9f4 authored by chaz's avatar chaz 👻
Browse files

Fix crash on shutdown

I'm not 100% sure why this fix works, but it does, and I'm still
fulfilling my obligations to free resources, so I'm rolling with it.

See the added comment for some more details.  Basically there seems to
be a problem with destroying the SDL renderer before destroying the
window, though that would appear to be the correct order of operations.
I'm not sure if I'm doing something wonky to cause the issue, but simply
rearranging the order of destruction makes the crash go away, so here we
parent 6f4c7545
......@@ -118,14 +118,24 @@ void b3_enter_window(
void b3_exit_window(void) {
b3_window_size = (b3_size){0, 0};
handle_input = NULL;
if(renderer) {
renderer = NULL;
if(window) {
window = NULL;
// Common sense (and examples from the SDL documentation wiki) suggest that
// it'd be correct to destroy the renderer *before* destroying the window.
// That's how this used to be arranged. However, at some point after the
// code had been working correctly for years, I noticed it had started
// crashing on shutdown, and traced it to SDL_DestroyRenderer(). I have
// *no idea* what's going on internally to cause a crash, or what changed
// over the years, but simply moving this call to after the window is
// destroyed makes the crash go away, and I believe I'm still cleaning up
// all allocated resources correctly, so maybe everything is fine. Fine!
if(renderer) {
renderer = NULL;
static int keysym_to_input(const SDL_Keysym *keysym) {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment