1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Possible fix for crash on attempt to free sdl surface in worked thread

This commit is contained in:
Ivan Savenko
2025-02-22 17:16:18 +00:00
parent ad68773f81
commit 1bc7c13204
3 changed files with 50 additions and 23 deletions

View File

@@ -12,6 +12,7 @@
#include "SDL_Extensions.h"
#include "../gui/CGuiHandler.h"
#include "../CMT.h"
#include "../xBRZ/xbrz.h"
@@ -227,12 +228,19 @@ SDLImageScaler::SDLImageScaler(SDL_Surface * surf, const Rect & virtualDimension
SDL_FreeSurface(intermediate);
intermediate = SDL_ConvertSurfaceFormat(surf, SDL_PIXELFORMAT_ARGB8888, 0);
}
if (intermediate == surf)
throw std::runtime_error("Scaler uses same surface as input!");
}
SDLImageScaler::~SDLImageScaler()
{
SDL_FreeSurface(intermediate);
SDL_FreeSurface(ret);
GH.dispatchMainThread([surface = intermediate]()
{
// potentially SDL bug, execute SDL_FreeSurface in main thread to avoid thread races to its internal state
// may be fixed somewhere between 2.26.5 - 2.30
SDL_FreeSurface(surface);
});
}
SDL_Surface * SDLImageScaler::acquireResultSurface()