← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1829623-assert_is_present into lp:widelands

 

Benedikt Straub has proposed merging lp:~widelands-dev/widelands/bug-1829623-assert_is_present into lp:widelands.

Commit message:
Do not send soldiers to attack if they are not stationed in a militarysite anymore

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1829623 in widelands: "Assertion `is_present(soldier)' failed"
  https://bugs.launchpad.net/widelands/+bug/1829623

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1829623-assert_is_present/+merge/367912
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1829623-assert_is_present into lp:widelands.
=== modified file 'src/logic/player.cc'
--- src/logic/player.cc	2019-05-11 18:19:20 +0000
+++ src/logic/player.cc	2019-05-24 16:26:59 +0000
@@ -962,8 +962,16 @@
 			if (const AttackTarget* attack_target = building->attack_target()) {
 				if (attack_target->can_be_attacked()) {
 					for (Soldier* temp_attacker : soldiers) {
-						upcast(MilitarySite, ms, temp_attacker->get_location(egbase()));
-						ms->send_attacker(*temp_attacker, *building);
+						assert(temp_attacker->get_owner() == this);
+						if (upcast(MilitarySite, ms, temp_attacker->get_location(egbase()))) {
+							assert(ms->get_owner() == this);
+							ms->send_attacker(*temp_attacker, *building);
+						} else {
+							// The soldier may not be in a militarysite anymore if he was kicked out
+							// in the short delay between sending and executing a playercommand
+							log("Player(%u)::enemyflagaction: Not sending soldier %u because he deserted\n",
+									player_number(), temp_attacker->serial());
+						}
 					}
 				}
 			}


Follow ups