Fix another crash on startup with SDL 2.0.6

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.
This commit is contained in:
Jyrki Vesterinen 2017-09-23 17:43:19 +03:00
parent dbd6695da9
commit bc911f8c46
2 changed files with 6 additions and 0 deletions

View file

@ -54,6 +54,9 @@ public:
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_; }

View file

@ -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);
}
}