From 265fc48d1590cdd503187c79dc254d65623c8d7b Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 24 Aug 2017 09:06:39 +0200 Subject: [PATCH] WAGE: Do something when player is not defined instead of crashes --- engines/wage/gui.cpp | 4 ++++ engines/wage/world.cpp | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 7d1014b9136..9c76418a591 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -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; diff --git a/engines/wage/world.cpp b/engines/wage/world.cpp index df9fcaf0229..c0c802ff8d7 100644 --- a/engines/wage/world.cpp +++ b/engines/wage/world.cpp @@ -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());