From bc911f8c466f61c6edeab1db52938e0bbc01d3dd Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Sat, 23 Sep 2017 17:43:19 +0300 Subject: [PATCH] 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. --- src/sdl/surface.hpp | 3 +++ src/video.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/sdl/surface.hpp b/src/sdl/surface.hpp index 8139bf7d680a..b45c6487bdbe 100644 --- a/src/sdl/surface.hpp +++ b/src/sdl/surface.hpp @@ -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_; } diff --git a/src/video.cpp b/src/video.cpp index edd4d402cb5d..5be0e524be77 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -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); } }