Fixed a crash when the attacker dies while performing a desparate attack.

The crash seemed only to happen under Windows but valgrind also
complained (bug #10496)
This commit is contained in:
Mark de Wever 2007-12-15 14:46:06 +00:00
parent 0fabf930b2
commit 65c891c5b4
4 changed files with 19 additions and 7 deletions

View File

@ -44,6 +44,9 @@ Version 1.3.12+svn:
* The MP server can send gzipped data depending on a hidden parameter
which is off by default.
* The campaign server sends and receives binary_wml.
* fixed a crash when the attacker dies while performing a desparate attack.
The crash seemed only to happen under Windows but valgrind also
complained (bug #10496)
Version 1.3.12:
* campaigns:

View File

@ -1071,7 +1071,19 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
}
}
void ai_interface::attack_enemy(const location& u, const location& target, int weapon, int def_weapon)
//! This function should be called to attack an enemy.
//!
//! @param u The location of the attacking unit. (Note this shouldn't
//! be a reference since attack::attack() can invalidate the
//! unit_map and references to the map are also invalid then.)
//! @param target The location of the target unit. This unit must be in
//! range of the attacking unit's weapon. (See note at param u.)
//! @param weapon The number of the weapon (0-based) which should be used
//! by the attacker. (It must be a valid weapon of the attacker.)
//! @param def_weapon The number of the weapon (0-based) which should be used
//! by the defender. (It must be a valid weapon of the defender.)
void ai_interface::attack_enemy(const location u,
const location target, int weapon, int def_weapon)
{
// Stop the user from issuing any commands while the unit is attacking
const events::command_disabler disable_commands;

View File

@ -103,12 +103,7 @@ public:
protected:
//! This function should be called to attack an enemy.
//! 'attacking_unit': the location of the attacking unit
//! 'target': the location of the target unit.
// This unit must be in range of the attacking unit's weapon
//! 'att_weapon': the number of the weapon (0-based) which should be used in the attack.
//! This must be a valid weapon of the attacking unit.
void attack_enemy(const location& attacking_unit, const location& target, int att_weapon, int def_weapon);
void attack_enemy(const location u, const location target, int att_weapon, int def_weapon);
//! This function should be called to move a unit.
//! Once the unit has been moved, its movement allowance is set to 0.

View File

@ -1026,6 +1026,8 @@ bool do_replay(game_display& disp, const gamemap& map, const game_data& gameinfo
replay::throw_error("no destination/source found in attack\n");
}
//we must get locations by value instead of by references, because the iterators
//may become invalidated later
const gamemap::location src(*source, game_events::get_state_of_game());
const gamemap::location dst(*destination, game_events::get_state_of_game());