Permalink
Browse files

Fixed a crash happening when a character had no weapon equipped.

The new status effect apply function was turning the weapon pointer
into a reference leading to a memory corruption when no weapon
was equipped.
  • Loading branch information...
1 parent 158e425 commit 9a44841374d08568efb797245149ee7b340d629c Yohann Ferreira committed Mar 30, 2013
Showing with 13 additions and 8 deletions.
  1. +12 −7 src/modes/battle/battle.cpp
  2. +1 −1 src/modes/battle/battle.h
@@ -846,30 +846,35 @@ static void SetEffectMaximum(GLOBAL_INTENSITY *max_effect, const std::vector<std
}
void BattleMode::_ApplyPassiveStatusEffects(private_battle::BattleActor &character,
- const hoa_global::GlobalWeapon &weapon,
- const std::vector<hoa_global::GlobalArmor *>& armors)
+ const hoa_global::GlobalWeapon* weapon,
+ const std::vector<hoa_global::GlobalArmor *>& armors)
{
//we only count the first 12 status effects as valid
//todo: allow a way for drain / regen
const static size_t MAX_VALID_STATUS = 12;
//max value array for each of the status types.
GLOBAL_INTENSITY max_effect[MAX_VALID_STATUS] = {GLOBAL_INTENSITY_INVALID};
+
//adjust effects for the weapons
- SetEffectMaximum(max_effect, weapon.GetStatusEffects());
+ if (weapon)
+ SetEffectMaximum(max_effect, weapon->GetStatusEffects());
+
//adjust effects for armor
for(std::vector<hoa_global::GlobalArmor *>::const_iterator itr = armors.begin(),
- end = armors.end(); itr != end; ++itr)
+ end = armors.end(); itr != end; ++itr) {
if((*itr))
SetEffectMaximum(max_effect, (*itr)->GetStatusEffects());
+ }
+
//go through each effect (as a pair) looking for the highest one.
for(size_t i = 0; i < MAX_VALID_STATUS; i += 2)
{
//no change for this status
- if(max_effect[i] == GLOBAL_INTENSITY_INVALID && max_effect[i+1] == GLOBAL_INTENSITY_INVALID)
+ if(max_effect[i] == GLOBAL_INTENSITY_INVALID && max_effect[i + 1] == GLOBAL_INTENSITY_INVALID)
continue;
GLOBAL_STATUS max_status;
GLOBAL_INTENSITY max_intensity;
- max_status = (int)max_effect[i] > (int)max_effect[i+1] ? (GLOBAL_STATUS)i : (GLOBAL_STATUS)(i + 1);
+ max_status = (int)max_effect[i] > (int)max_effect[i + 1] ? (GLOBAL_STATUS)i : (GLOBAL_STATUS)(i + 1);
max_intensity = max_effect[(size_t)max_status];
if(max_intensity == GLOBAL_INTENSITY_NEUTRAL)
continue;
@@ -886,7 +891,7 @@ void BattleMode::_ApplyPassiveStatusEffects(private_battle::BattleActor &charact
void BattleMode::_ResetPassiveStatusEffects(hoa_battle::private_battle::BattleActor &character)
{
_ResetAttributesFromGlobalActor(character);
- _ApplyPassiveStatusEffects(character, *(character.GetGlobalActor()->GetWeaponEquipped()), character.GetGlobalActor()->GetArmorEquipped());
+ _ApplyPassiveStatusEffects(character, character.GetGlobalActor()->GetWeaponEquipped(), character.GetGlobalActor()->GetArmorEquipped());
}
void BattleMode::SetActorIdleStateTime(BattleActor *actor)
@@ -541,7 +541,7 @@ class BattleMode : public hoa_mode_manager::GameMode
//! to the character.
//! \note this does not effect the global character, but only for the duration of the battle
void _ApplyPassiveStatusEffects(private_battle::BattleActor &character,
- const hoa_global::GlobalWeapon &weapon,
+ const hoa_global::GlobalWeapon* weapon,
const std::vector<hoa_global::GlobalArmor *>& armors);
//! \brief resets the actor to their global status values, and then applies

0 comments on commit 9a44841

Please sign in to comment.