Skip to content

Commit

Permalink
Fix another crash on startup with SDL 2.0.6
Browse files Browse the repository at this point in the history
Caused by the same commit. SDL freed the old framebuffer even though we had
a reference to it, and when we passed it to SDL_FreeSurface(), it attempted
to free it again. It resulted in a crash depending on the C standard
library implementation and optimization level.
  • Loading branch information
jyrkive committed Sep 23, 2017
1 parent dbd6695 commit bc911f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sdl/surface.hpp
Expand Up @@ -54,6 +54,9 @@ class surface
return *this;
}

// Intended to be used when SDL has already freed the surface
void clear_without_free() { surface_ = nullptr; }

operator SDL_Surface*() const { return surface_; }

SDL_Surface* get() const { return surface_; }
Expand Down
3 changes: 3 additions & 0 deletions src/video.cpp
Expand Up @@ -196,6 +196,9 @@ void CVideo::update_framebuffer()
if(!frameBuffer) {
frameBuffer = fb;
} else {
// Because SDL has already freed the old framebuffer,
// ensure that we won't attempt to free it.
frameBuffer.clear_without_free();
frameBuffer.assign(fb);
}
}
Expand Down

0 comments on commit bc911f8

Please sign in to comment.