Skip to content

Commit

Permalink
Restricts minimum texture size to fix crash during division by zero
Browse files Browse the repository at this point in the history
- restricts minimum texture size to 128 sprites wide and 256 sprites high;
- adds debug message about 0 `max_texture`-dimensions.

Fixes CleverRaven#22596
  • Loading branch information
ZhilkinSerg committed Dec 18, 2017
1 parent a2cff93 commit 329dcc4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 329dcc4

Please sign in to comment.