← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1795976-port-attack-crash into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1795976-port-attack-crash into lp:widelands.

Commit message:
Fix endless loop in DefaultAI::dispensable_road_test

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1795976 in widelands: "Crash, game freezes, memory overflow"
  https://bugs.launchpad.net/widelands/+bug/1795976

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1795976-port-attack-crash/+merge/356454
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1795976-port-attack-crash into lp:widelands.
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2018-09-29 14:35:29 +0000
+++ src/ai/defaultai.cc	2018-10-11 06:58:14 +0000
@@ -3593,6 +3593,7 @@
 	uint16_t road_length = road.get_path().get_nsteps();
 
 	for (int j = 0; j < 2; ++j) {
+		std::set<Widelands::Serial> visited_flags;
 		bool new_road_found = true;
 		while (new_road_found && full_road.back()->nr_of_roads() <= 2 &&
 		       full_road.back()->get_building() == nullptr) {
@@ -3616,10 +3617,16 @@
 				if (other_end->get_position() == full_road[full_road_size - 2]->get_position()) {
 					continue;
 				}
-				full_road.push_back(other_end);
-				road_length += near_road->get_path().get_nsteps();
-				new_road_found = true;
-				break;
+
+				// Do not visit the same flag twice
+				if (visited_flags.count(other_end->serial()) == 0) {
+					// We have found a new flag to add to the road
+					full_road.push_back(other_end);
+					road_length += near_road->get_path().get_nsteps();
+					new_road_found = true;
+					visited_flags.insert(other_end->serial());
+					break;
+				}
 			}
 		}
 		// we walked to one end, now let revert the concent of full_road and repeat in opposite


Follow ups