WAGE: Do something when player is not defined instead of crashes

This commit is contained in:
Eugene Sandulenko 2017-08-24 09:06:39 +02:00
parent 7cf83cab6a
commit 265fc48d15
2 changed files with 20 additions and 2 deletions

View File

@ -209,6 +209,10 @@ void Gui::regenWeaponsMenu() {
_menu->clearSubMenu(_weaponsMenuId);
Chr *player = _engine->_world->_player;
if (!player) {
warning("regenWeaponsMenu: player is not defined");
return;
}
ObjArray *weapons = player->getWeapons(true);
bool empty = true;

View File

@ -252,11 +252,25 @@ bool World::loadWorld(Common::MacResManager *resMan) {
Chr *chr = new Chr(resMan->getResName(MKTAG('A','C','H','R'), *iter), res);
chr->_resourceId = *iter;
addChr(chr);
// TODO: What if there's more than one player character?
if (chr->_playerCharacter)
if (chr->_playerCharacter) {
if (_player)
warning("loadWorld: Player is redefined");
_player = chr;
}
}
if (!_player) {
warning("loadWorld: Player is not defined");
if (_chrs.empty()) {
error("loadWorld: and I have no characters");
}
_player = _chrs[0];
}
// Load Sounds
resArray = resMan->getResIDArray(MKTAG('A','S','N','D'));
debug(3, "Loading %d sounds", resArray.size());