← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1782593-segfault-random-map into lp:widelands

 

Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1782593-segfault-random-map into lp:widelands.

Commit message:
Fixing failed assert in random map generator and fixing bug in code for selection of start position.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1782593 in widelands: "Segfault in random map generator"
  https://bugs.launchpad.net/widelands/+bug/1782593

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1782593-segfault-random-map/+merge/350384

Fixing the broken assert was a simple case of too late initialization.

The fixed bug regarding the starting position was an unrelated bug which resulted in the map generator nearly always failing to find a valid start position for a player. Due to the wrong initialization of the min_distance the following comparison always failed to accept one of the valid positions as start position.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1782593-segfault-random-map into lp:widelands.
=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc	2018-05-11 04:48:10 +0000
+++ src/editor/map_generator.cc	2018-07-21 08:03:23 +0000
@@ -659,9 +659,10 @@
 	map_.recalc_whole_map(egbase_.world());
 
 	// Care about players and place their start positions
+	map_.set_nrplayers(map_info_.numPlayers);
+	assert(map_info_.numPlayers >= 1);
 	const std::string tribe = map_.get_scenario_player_tribe(1);
 	const std::string ai = map_.get_scenario_player_ai(1);
-	map_.set_nrplayers(map_info_.numPlayers);
 	FindNodeSize functor(FindNodeSize::sizeBig);
 	Coords playerstart(Coords::null());
 
@@ -754,7 +755,7 @@
 		map_.find_fields(Area<FCoords>(map_.get_fcoords(playerstart), 20), &coords, functor);
 
 		// Take the nearest ones
-		uint32_t min_distance = 0;
+		uint32_t min_distance = std::numeric_limits<uint32_t>::max();
 		Coords coords2;
 		for (uint16_t i = 0; i < coords.size(); ++i) {
 			uint32_t test = map_.calc_distance(coords[i], playerstart);


Follow ups