From 38c1542d9d8e7c57d6b682c58b2421811aea8a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 18 Aug 2013 17:49:31 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20crash=20on=20battle=20end=20=E2=80=94?= =?UTF-8?q?=20don't=20attempt=20giving=20exp=20to=20loser=20(hero=20is=20r?= =?UTF-8?q?emoved=20->=20can't=20get=20exp=20->=20crash).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/CGameHandler.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 58316e71f..2de72030f 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -628,9 +628,9 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer } //give exp - if (battleResult.data->exp[0] && hero1) + if (battleResult.data->exp[0] && hero1 && battleResult.get()->winner == 0) changePrimSkill(hero1, PrimarySkill::EXPERIENCE, battleResult.data->exp[0]); - else if (battleResult.data->exp[1] && hero2) + else if (battleResult.data->exp[1] && hero2 && battleResult.get()->winner == 1) changePrimSkill(hero2, PrimarySkill::EXPERIENCE, battleResult.data->exp[1]); queries.popIfTop(battleQuery); @@ -3536,6 +3536,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) StartAction start_action(ba); sendAndApply(&start_action); + auto makeScopeGuard([&]{ sendAndApply(&end_action); }); //if we started than we have to finish + const CGHeroInstance * attackingHero = gs->curB->battleGetFightingHero(ba.side); CHeroHandler::SBallisticsLevelInfo sbi = VLC->heroh->ballistics[attackingHero->getSecSkillLevel(SecondarySkill::BALLISTICS)]; @@ -3547,11 +3549,13 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) } //in successive iterations damage is dealt but not yet subtracted from wall's HPs - auto currentHP = gs->curB->si.wallState; + auto ¤tHP = gs->curB->si.wallState; - if (currentHP[desiredTarget] != EWallState::DESTROYED && - currentHP[desiredTarget] != EWallState::NONE) - desiredTarget = EWallParts::INVALID; + if (currentHP[desiredTarget] == EWallState::DESTROYED || currentHP[desiredTarget] == EWallState::NONE) + { + complain("catapult tried to attack already destroyed wall part!"); + break; + } for(int g=0; g