aboutsummaryrefslogtreecommitdiff
path: root/engines/hdb
diff options
context:
space:
mode:
authorEugene Sandulenko2019-08-24 22:54:57 +0200
committerEugene Sandulenko2019-09-03 17:17:35 +0200
commit36c2b15ab92ba84e4de0353b2622272606491684 (patch)
treeb0e771cb1c5b418f0f58019ed87b5b98a99dcd78 /engines/hdb
parent83d3af60091263d78df05121d67c8945fca76a5a (diff)
downloadscummvm-rg350-36c2b15ab92ba84e4de0353b2622272606491684.tar.gz
scummvm-rg350-36c2b15ab92ba84e4de0353b2622272606491684.tar.bz2
scummvm-rg350-36c2b15ab92ba84e4de0353b2622272606491684.zip
HDB: Fix out-of-bound access when on the edge of map
Diffstat (limited to 'engines/hdb')
-rw-r--r--engines/hdb/map.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/engines/hdb/map.cpp b/engines/hdb/map.cpp
index e309b57333..9f62fb8bbb 100644
--- a/engines/hdb/map.cpp
+++ b/engines/hdb/map.cpp
@@ -868,10 +868,14 @@ void Map::draw() {
int maxTileX = (_mapTileXOff >= -8) ? g_hdb->_map->_screenXTiles - 1 : g_hdb->_map->_screenXTiles;
int maxTileY = (!_mapTileYOff) ? g_hdb->_map->_screenYTiles - 1 : g_hdb->_map->_screenYTiles;
- if (matrixY + (maxTileY - 1)*_width > _height * _width) {
+ if (matrixY + (maxTileY - 1) * _width > _height * _width) {
return;
}
+ // Sometimes we're 1 beyond the map, so avoid it
+ if (_mapTileX + maxTileX - 1 >= _width)
+ maxTileX--;
+
_numForegrounds = _numGratings = 0;
for (int j = 0; j < maxTileY; j++) {
@@ -886,7 +890,11 @@ void Map::draw() {
// Draw if not a sky tile
if (!g_hdb->_gfx->isSky(tileIndex)) {
- g_hdb->_gfx->getTile(tileIndex)->draw(screenX, screenY);
+ Tile *tile = g_hdb->_gfx->getTile(tileIndex);
+ if (tile)
+ tile->draw(screenX, screenY);
+ else
+ warning("Cannot find tile with index %d at %d,%d", tileIndex, _mapTileX + i, _mapTileY + j);
}
// Draw Foreground Tile