From 329dcc461c40ee1dcf2110a6c1b8c6a95443ac3f Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Mon, 18 Dec 2017 20:53:01 +0300 Subject: [PATCH] Restricts minimum texture size to fix crash during division by zero - restricts minimum texture size to 128 sprites wide and 256 sprites high; - adds debug message about 0 `max_texture`-dimensions. Fixes #22596 --- src/cata_tiles.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 8197d5e934d40..53c84d26a81a4 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -425,6 +425,19 @@ void tileset_loader::load_tileset( std::string img_path ) info.max_texture_height = sprite_height * 20 + 1; #endif + const int min_tile_xcount = 128; + const int min_tile_ycount = min_tile_xcount * 2; + + if( info.max_texture_width == 0 ){ + info.max_texture_width = sprite_width * min_tile_xcount; + DebugLog( D_INFO, DC_ALL ) << "SDL_RendererInfo max_texture_width was set to 0. Changing it to " << info.max_texture_width; + } + + if( info.max_texture_height == 0 ){ + info.max_texture_height = sprite_height * min_tile_ycount; + DebugLog( D_INFO, DC_ALL ) << "SDL_RendererInfo max_texture_height was set to 0. Changing it to " << info.max_texture_height; + } + // Number of tiles in each dimension that fits into a (maximal) SDL texture. // If the tile atlas contains more than that, we have to split it. const int max_tile_xcount = info.max_texture_width / sprite_width;