1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

do not leak screen surface etc. on quit

This commit is contained in:
AlexVinS
2016-08-30 03:43:49 +03:00
parent 2018b4d406
commit 4bc27194dd

View File

@@ -949,22 +949,8 @@ static bool checkVideoMode(int monitorIndex, int w, int h)
return false; return false;
} }
static bool recreateWindow(int w, int h, int bpp, bool fullscreen) static void cleanupRenderer()
{ {
// VCMI will only work with 2 or 4 bytes per pixel
vstd::amax(bpp, 16);
vstd::amin(bpp, 32);
if(bpp>16)
bpp = 32;
if(!checkVideoMode(0,w,h))
{
logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!";
return false;
}
bool bufOnScreen = (screenBuf == screen);
screenBuf = nullptr; //it`s a link - just nullify screenBuf = nullptr; //it`s a link - just nullify
if(nullptr != screen2) if(nullptr != screen2)
@@ -973,14 +959,12 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
screen2 = nullptr; screen2 = nullptr;
} }
if(nullptr != screen) if(nullptr != screen)
{ {
SDL_FreeSurface(screen); SDL_FreeSurface(screen);
screen = nullptr; screen = nullptr;
} }
if(nullptr != screenTexture) if(nullptr != screenTexture)
{ {
SDL_DestroyTexture(screenTexture); SDL_DestroyTexture(screenTexture);
@@ -998,7 +982,25 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
SDL_DestroyWindow(mainWindow); SDL_DestroyWindow(mainWindow);
mainWindow = nullptr; mainWindow = nullptr;
} }
}
static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
{
// VCMI will only work with 2 or 4 bytes per pixel
vstd::amax(bpp, 16);
vstd::amin(bpp, 32);
if(bpp>16)
bpp = 32;
if(!checkVideoMode(0,w,h))
{
logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!";
return false;
}
bool bufOnScreen = (screenBuf == screen);
cleanupRenderer();
if(fullscreen) if(fullscreen)
{ {
@@ -1011,8 +1013,6 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, w, h, 0); mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, w, h, 0);
} }
if(nullptr == mainWindow) if(nullptr == mainWindow)
{ {
throw std::runtime_error("Unable to create window\n"); throw std::runtime_error("Unable to create window\n");
@@ -1279,7 +1279,10 @@ void handleQuit(bool ask/* = true*/)
vstd::clear_pointer(console); vstd::clear_pointer(console);
boost::this_thread::sleep(boost::posix_time::milliseconds(750)); boost::this_thread::sleep(boost::posix_time::milliseconds(750));
if(!gNoGUI) if(!gNoGUI)
{
cleanupRenderer();
SDL_Quit(); SDL_Quit();
}
std::cout << "Ending...\n"; std::cout << "Ending...\n";
exit(0); exit(0);