mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Do proper error handling inside Screen::ResizeScreen()
Instead of passing the error codes out of the function, just handle the errors directly as they happen, and fail gracefully if something goes wrong instead of continuing.
This commit is contained in:
@@ -89,10 +89,8 @@ Screen::Screen()
|
||||
glScreen = true;
|
||||
}
|
||||
|
||||
int Screen::ResizeScreen(int x, int y)
|
||||
void Screen::ResizeScreen(int x, int y)
|
||||
{
|
||||
int result = 0; // 0 is success, nonzero is failure
|
||||
|
||||
static int resX = 320;
|
||||
static int resY = 240;
|
||||
if (x != -1 && y != -1)
|
||||
@@ -104,11 +102,21 @@ int Screen::ResizeScreen(int x, int y)
|
||||
|
||||
if(!isWindowed)
|
||||
{
|
||||
result = SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
int result = SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("Error: could not set the game to fullscreen mode: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = SDL_SetWindowFullscreen(m_window, 0);
|
||||
int result = SDL_SetWindowFullscreen(m_window, 0);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("Error: could not set the game to windowed mode: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
if (x != -1 && y != -1)
|
||||
{
|
||||
SDL_SetWindowSize(m_window, resX, resY);
|
||||
@@ -119,17 +127,30 @@ int Screen::ResizeScreen(int x, int y)
|
||||
{
|
||||
int winX, winY;
|
||||
SDL_GetWindowSize(m_window, &winX, &winY);
|
||||
SDL_RenderSetLogicalSize(m_renderer, winX, winY);
|
||||
int result = SDL_RenderSetLogicalSize(m_renderer, winX, winY);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("Error: could not set logical size: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
result = SDL_RenderSetIntegerScale(m_renderer, SDL_FALSE);
|
||||
if (result != 0)
|
||||
{
|
||||
printf("Error: could not set scale: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RenderSetLogicalSize(m_renderer, 320, 240);
|
||||
result = SDL_RenderSetIntegerScale(m_renderer, (SDL_bool) (stretchMode == 2));
|
||||
int result = SDL_RenderSetIntegerScale(m_renderer, (SDL_bool) (stretchMode == 2));
|
||||
if (result != 0)
|
||||
{
|
||||
printf("Error: could not set scale: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
}
|
||||
SDL_ShowWindow(m_window);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Screen::GetWindowSize(int* x, int* y)
|
||||
@@ -184,11 +205,10 @@ void Screen::FlipScreen()
|
||||
SDL_FillRect(m_screen, NULL, 0x00000000);
|
||||
}
|
||||
|
||||
int Screen::toggleFullScreen()
|
||||
void Screen::toggleFullScreen()
|
||||
{
|
||||
isWindowed = !isWindowed;
|
||||
int result = ResizeScreen(-1, -1);
|
||||
return result;
|
||||
ResizeScreen(-1, -1);
|
||||
}
|
||||
|
||||
void Screen::toggleStretchMode()
|
||||
|
||||
Reference in New Issue
Block a user