← Back to team overview

widelands-dev team mailing list archive

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

 

TiborB has proposed merging lp:~widelands-dev/widelands/bug-1530999 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1530999 in widelands: "Crash in defaultai"
  https://bugs.launchpad.net/widelands/+bug/1530999

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1530999/+merge/281691

Fixing crash in AI, function check_enemy_sites()
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1530999 into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2016-01-02 12:36:38 +0000
+++ src/ai/defaultai.cc	2016-01-05 21:02:19 +0000
@@ -5351,6 +5351,8 @@
 	uint32_t best_target = std::numeric_limits<uint32_t>::max();
 	uint8_t best_score = 0;
 	uint32_t count = 0;
+	// sites that were either conquered or destroyed
+	std::vector<uint32_t> disappeared_sites;
 
 	for (std::map<uint32_t, EnemySiteObserver>::iterator site = enemy_sites.begin();
 	     site != enemy_sites.end();
@@ -5510,11 +5512,15 @@
 		}
 
 		if (site_to_be_removed < std::numeric_limits<uint32_t>::max()) {
-			enemy_sites.erase(site_to_be_removed);
-			continue;
+			disappeared_sites.push_back(site_to_be_removed);
 		}
 	}
 
+	while (!disappeared_sites.empty()) {
+		enemy_sites.erase(disappeared_sites.back());
+		disappeared_sites.pop_back();
+	}
+
 	// modifying enemysites_check_delay_,this depends on the count
 	// of enemysites in observer
 	if (count >= 13 && enemysites_check_delay_ < 180) {
@@ -5529,6 +5535,8 @@
 		return false;
 	}
 
+	assert(enemy_sites.count(best_target) > 0);
+
 	// attacking
 	FCoords f = map.get_fcoords(coords_unhash(best_target));
 	// setting no attack counter here


Follow ups