From 9b275a5077392f57d48212869c89d42973647315 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 10 Jan 2011 06:43:47 +0000 Subject: [PATCH] - added guard against NULL commandtype clicking in icon panel (discovered during testing) --- source/glest_game/gui/gui.cpp | 17 +++++++++-------- source/glest_game/type_instances/faction.cpp | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index fc9bf7f71..cf1b954a0 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -552,19 +552,20 @@ void Gui::clickCommonCommand(CommandClass commandClass){ } } -void Gui::mouseDownDisplayUnitSkills(int posDisplay){ - if(!selection.isEmpty()){ - if(posDisplay != cancelPos){ - if(posDisplay!=meetingPointPos){ +void Gui::mouseDownDisplayUnitSkills(int posDisplay) { + if(!selection.isEmpty()) { + if(posDisplay != cancelPos) { + if(posDisplay!=meetingPointPos) { const Unit *unit= selection.getFrontUnit(); //uniform selection - if(selection.isUniform()){ - if(unit->getFaction()->reqsOk(display.getCommandType(posDisplay))){ + if(selection.isUniform()) { + const CommandType *ct = display.getCommandType(posDisplay); + if(ct != NULL && unit->getFaction()->reqsOk(ct)) { activeCommandType= display.getCommandType(posDisplay); activeCommandClass= activeCommandType->getClass(); } - else{ + else { posDisplay= invalidPos; activeCommandType= NULL; activeCommandClass= ccStop; @@ -573,7 +574,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay){ } //non uniform selection - else{ + else { activeCommandType= NULL; activeCommandClass= display.getCommandClass(posDisplay); } diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index cc8099533..139046dd6 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -213,6 +213,10 @@ int Faction::getCountForMaxUnitCount(const UnitType *unitType) const{ bool Faction::reqsOk(const CommandType *ct) const { assert(ct != NULL); + if(ct == NULL) { + throw runtime_error("In [Faction::reqsOk] ct == NULL"); + } + if(ct->getProduced() != NULL && reqsOk(ct->getProduced()) == false) { return false; }