mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49:43 +01: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:
parent
9175c08763
commit
cad0b4fcc4
3 changed files with 35 additions and 20 deletions
|
@ -89,10 +89,8 @@ Screen::Screen()
|
||||||
glScreen = true;
|
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 resX = 320;
|
||||||
static int resY = 240;
|
static int resY = 240;
|
||||||
if (x != -1 && y != -1)
|
if (x != -1 && y != -1)
|
||||||
|
@ -104,11 +102,21 @@ int Screen::ResizeScreen(int x, int y)
|
||||||
|
|
||||||
if(!isWindowed)
|
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
|
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)
|
if (x != -1 && y != -1)
|
||||||
{
|
{
|
||||||
SDL_SetWindowSize(m_window, resX, resY);
|
SDL_SetWindowSize(m_window, resX, resY);
|
||||||
|
@ -119,17 +127,30 @@ int Screen::ResizeScreen(int x, int y)
|
||||||
{
|
{
|
||||||
int winX, winY;
|
int winX, winY;
|
||||||
SDL_GetWindowSize(m_window, &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);
|
result = SDL_RenderSetIntegerScale(m_renderer, SDL_FALSE);
|
||||||
|
if (result != 0)
|
||||||
|
{
|
||||||
|
printf("Error: could not set scale: %s\n", SDL_GetError());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_RenderSetLogicalSize(m_renderer, 320, 240);
|
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);
|
SDL_ShowWindow(m_window);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::GetWindowSize(int* x, int* y)
|
void Screen::GetWindowSize(int* x, int* y)
|
||||||
|
@ -184,11 +205,10 @@ void Screen::FlipScreen()
|
||||||
SDL_FillRect(m_screen, NULL, 0x00000000);
|
SDL_FillRect(m_screen, NULL, 0x00000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Screen::toggleFullScreen()
|
void Screen::toggleFullScreen()
|
||||||
{
|
{
|
||||||
isWindowed = !isWindowed;
|
isWindowed = !isWindowed;
|
||||||
int result = ResizeScreen(-1, -1);
|
ResizeScreen(-1, -1);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::toggleStretchMode()
|
void Screen::toggleStretchMode()
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Screen
|
||||||
public:
|
public:
|
||||||
Screen();
|
Screen();
|
||||||
|
|
||||||
int ResizeScreen(int x, int y);
|
void ResizeScreen(int x, int y);
|
||||||
void GetWindowSize(int* x, int* y);
|
void GetWindowSize(int* x, int* y);
|
||||||
|
|
||||||
void UpdateScreen(SDL_Surface* buffer, SDL_Rect* rect);
|
void UpdateScreen(SDL_Surface* buffer, SDL_Rect* rect);
|
||||||
|
@ -17,7 +17,7 @@ public:
|
||||||
|
|
||||||
const SDL_PixelFormat* GetFormat();
|
const SDL_PixelFormat* GetFormat();
|
||||||
|
|
||||||
int toggleFullScreen();
|
void toggleFullScreen();
|
||||||
void toggleStretchMode();
|
void toggleStretchMode();
|
||||||
void toggleLinearFilter();
|
void toggleLinearFilter();
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ int main(int argc, char *argv[])
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = gameScreen.toggleFullScreen();
|
gameScreen.toggleFullScreen();
|
||||||
game.fullscreen = !game.fullscreen;
|
game.fullscreen = !game.fullscreen;
|
||||||
key.toggleFullscreen = false;
|
key.toggleFullscreen = false;
|
||||||
|
|
||||||
|
@ -334,11 +334,6 @@ int main(int argc, char *argv[])
|
||||||
game.press_right = false;
|
game.press_right = false;
|
||||||
game.press_action = true;
|
game.press_action = true;
|
||||||
game.press_map = false;
|
game.press_map = false;
|
||||||
|
|
||||||
if(result != 0)
|
|
||||||
{
|
|
||||||
printf("Error: toggling fullscreen failed: %s\n", SDL_GetError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
game.infocus = key.isActive;
|
game.infocus = key.isActive;
|
||||||
|
|
Loading…
Reference in a new issue