Show error message instead of aborting when loading an invalid map size.

pull/3/head
Jonathan G Rennison 9 years ago
parent 1891e7dfc8
commit f27ca88596

@ -32,17 +32,14 @@ uint _map_tile_mask; ///< _map_size - 1 (to mask the mapsize)
Tile *_m = NULL; ///< Tiles of the map
TileExtended *_me = NULL; ///< Extended Tiles of the map
/**
* (Re)allocates a map with the given dimension
* Validates whether a map with the given dimension is valid
* @param size_x the width of the map along the NE/SW edge
* @param size_y the 'height' of the map along the SE/NW edge
* @return true if valid, or false if not valid
*/
void AllocateMap(uint size_x, uint size_y)
bool ValidateMapSize(uint size_x, uint size_y)
{
DEBUG(map, 2, "Min/max map size %d/%d, max map tiles %d", MIN_MAP_SIZE, MAX_MAP_SIZE, MAX_MAP_TILES);
DEBUG(map, 1, "Allocating map of size %dx%d", size_x, size_y);
/* Make sure that the map size is within the limits and that
* size of both axes is a power of 2. */
if (size_x * size_y > MAX_MAP_TILES ||
@ -50,6 +47,22 @@ void AllocateMap(uint size_x, uint size_y)
size_y < MIN_MAP_SIZE ||
(size_x & (size_x - 1)) != 0 ||
(size_y & (size_y - 1)) != 0) {
return false;
}
return true;
}
/**
* (Re)allocates a map with the given dimension
* @param size_x the width of the map along the NE/SW edge
* @param size_y the 'height' of the map along the SE/NW edge
*/
void AllocateMap(uint size_x, uint size_y)
{
DEBUG(map, 2, "Min/max map size %d/%d, max map tiles %d", MIN_MAP_SIZE, MAX_MAP_SIZE, MAX_MAP_TILES);
DEBUG(map, 1, "Allocating map of size %dx%d", size_x, size_y);
if (!ValidateMapSize(size_x, size_y)) {
error("Invalid map size");
}

@ -43,6 +43,7 @@ extern Tile *_m;
*/
extern TileExtended *_me;
bool ValidateMapSize(uint size_x, uint size_y);
void AllocateMap(uint size_x, uint size_y);
/**

@ -37,6 +37,9 @@ static void Save_MAPS()
static void Load_MAPS()
{
SlGlobList(_map_dimensions);
if (!ValidateMapSize(_map_dim_x, _map_dim_y)) {
SlErrorCorruptFmt("Invalid map size: %u x %u", _map_dim_x, _map_dim_y);
}
AllocateMap(_map_dim_x, _map_dim_y);
}

Loading…
Cancel
Save