mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-07-07 11:35:00 +00:00
Fix uncommon division-by-zero
Every now and then, the game crashes for me because of a division by zero, due to the rect returned by `Graphics::get_stretch_info`. I don't fully know how the width and height get set to 0, but this should protect against it. As I always use integer scaling, my guess is that `Screen::GetScreenSize` (which later calls `SDL_GetRendererOutputSize`) returns 0 sometimes, and the code trusts that -- but I know that windows and things can be finicky, so the clamp is probably a good idea.
This commit is contained in:
parent
6810c5fa8c
commit
719ed9a67b
1 changed files with 4 additions and 1 deletions
|
@ -3536,12 +3536,15 @@ void Graphics::get_stretch_info(SDL_Rect* rect)
|
|||
break;
|
||||
default:
|
||||
SDL_assert(0 && "Invalid scaling mode!");
|
||||
/* Width and height should be nonzero to avoid division by zero. */
|
||||
rect->x = 0;
|
||||
rect->y = 0;
|
||||
rect->w = width;
|
||||
rect->h = height;
|
||||
}
|
||||
|
||||
// In case anything accidentally set the width/height to 0, we'll clamp it to avoid crashing from a division by 0
|
||||
rect->w = SDL_max(1, rect->w);
|
||||
rect->h = SDL_max(1, rect->h);
|
||||
}
|
||||
|
||||
void Graphics::render(void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue