diff options
author | Sven Hesse | 2007-04-27 21:25:03 +0000 |
---|---|---|
committer | Sven Hesse | 2007-04-27 21:25:03 +0000 |
commit | f479aa73bab5717f49844daf53c07a957627389e (patch) | |
tree | a6b994f115a7154738803c4943ea280cd7218e82 /engines | |
parent | da93916adc1ff8b89eecc024dd7d8788df7cd1d2 (diff) | |
download | scummvm-rg350-f479aa73bab5717f49844daf53c07a957627389e.tar.gz scummvm-rg350-f479aa73bab5717f49844daf53c07a957627389e.tar.bz2 scummvm-rg350-f479aa73bab5717f49844daf53c07a957627389e.zip |
That should fix another segfault when clicking outside of the screen (bug #1708863)
svn-id: r26629
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gob/goblin.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/engines/gob/goblin.cpp b/engines/gob/goblin.cpp index 61dfbaff31..4620afabaa 100644 --- a/engines/gob/goblin.cpp +++ b/engines/gob/goblin.cpp @@ -977,39 +977,48 @@ void Goblin::moveFindItem(int16 posX, int16 posY) { break; } - _pressedMapX = posX / 12; - _pressedMapY = posY / 6; + _pressedMapX = CLIP(posX / 12, 0, _vm->_map->_mapWidth - 1); + _pressedMapY = CLIP(posY / 6, 0, _vm->_map->_mapHeight - 1); if ((_vm->_map->_itemsMap[_pressedMapY][_pressedMapX] == 0) && (i < 20)) { - if (_vm->_map->_itemsMap[_pressedMapY + 1][_pressedMapX] != 0) { + if ((_pressedMapY < (_vm->_map->_mapHeight - 1)) && + (_vm->_map->_itemsMap[_pressedMapY + 1][_pressedMapX] != 0)) { _pressedMapY++; - } else if (_vm->_map->_itemsMap[_pressedMapY + 1][_pressedMapX + 1] != 0) { + } else if ((_pressedMapX < (_vm->_map->_mapWidth - 1)) && + (_pressedMapY < (_vm->_map->_mapHeight - 1)) && + (_vm->_map->_itemsMap[_pressedMapY + 1][_pressedMapX + 1] != 0)) { _pressedMapX++; _pressedMapY++; - } else if (_vm->_map->_itemsMap[_pressedMapY][_pressedMapX + 1] != 0) { + } else if ((_pressedMapX < (_vm->_map->_mapWidth - 1)) && + (_vm->_map->_itemsMap[_pressedMapY][_pressedMapX + 1] != 0)) { _pressedMapX++; - } else if (_vm->_map->_itemsMap[_pressedMapY - 1][_pressedMapX + 1] != 0) { + } else if ((_pressedMapX < (_vm->_map->_mapWidth - 1)) && + (_pressedMapY > 0) && + (_vm->_map->_itemsMap[_pressedMapY - 1][_pressedMapX + 1] != 0)) { _pressedMapX++; _pressedMapY--; - } else if (_vm->_map->_itemsMap[_pressedMapY - 1][_pressedMapX] != 0) { + } else if ((_pressedMapY > 0) && + (_vm->_map->_itemsMap[_pressedMapY - 1][_pressedMapX] != 0)) { _pressedMapY--; - } else if (_vm->_map->_itemsMap[_pressedMapY - 1][_pressedMapX - 1] != 0) { + } else if ((_pressedMapY > 0) && (_pressedMapX > 0) && + (_vm->_map->_itemsMap[_pressedMapY - 1][_pressedMapX - 1] != 0)) { _pressedMapY--; _pressedMapX--; - } else if (_vm->_map->_itemsMap[_pressedMapY][_pressedMapX - 1] != 0) { + } else if ((_pressedMapX > 0) && + (_vm->_map->_itemsMap[_pressedMapY][_pressedMapX - 1] != 0)) { _pressedMapX--; - } else if (_vm->_map->_itemsMap[_pressedMapY + 1][_pressedMapX - 1] != 0) { + } else if ((_pressedMapX > 0) && + (_pressedMapY < (_vm->_map->_mapHeight - 1)) && + (_vm->_map->_itemsMap[_pressedMapY + 1][_pressedMapX - 1] != 0)) { _pressedMapX--; _pressedMapY++; } } } else { - _pressedMapX = posX / 12; - _pressedMapY = posY / 6; + _pressedMapX = CLIP(posX / 12, 0, _vm->_map->_mapWidth - 1); + _pressedMapY = CLIP(posY / 6, 0, _vm->_map->_mapHeight - 1); } - _pressedMapX = CLIP((int) _pressedMapX, 0, _vm->_map->_mapWidth - 1); - _pressedMapY = CLIP((int) _pressedMapY, 0, _vm->_map->_mapHeight - 1); } void Goblin::moveCheckSelect(int16 framesCount, Gob_Object *gobDesc, |