← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/fix-bug-1735980-related-problems into lp:widelands

 

Jukka Pakarinen has proposed merging lp:~widelands-dev/widelands/fix-bug-1735980-related-problems into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1735980 in widelands: "use-after-free in editor"
  https://bugs.launchpad.net/widelands/+bug/1735980

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fix-bug-1735980-related-problems/+merge/335403

The branch includes bug fixes described on bug 1735980.

The original problem of the bug 1735980 was heap-use-after-free found when the game was run with asan library and undo was applied to water with fish. The other problem concerned an applied immovable (ruin) moved to an unexpected posion on the map when the origin if the map was set.

The commit messages explain shortly why it fixes the bug.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/fix-bug-1735980-related-problems into lp:widelands.
=== modified file 'src/editor/tools/set_origin_tool.cc'
--- src/editor/tools/set_origin_tool.cc	2017-08-17 15:34:45 +0000
+++ src/editor/tools/set_origin_tool.cc	2017-12-19 18:24:38 +0000
@@ -41,7 +41,14 @@
                                       EditorActionArgs* /* args */,
                                       Widelands::Map* map) {
 	Widelands::Coords nc(
-	   map->get_width() - 1 - center.node.x, map->get_height() - 1 - center.node.y);
+	   map->get_width() - center.node.x, map->get_height() - center.node.y);
+
+	// Because of the triangle design of map, y is changed by an odd number.
+	// The x must be syncronized with the y when coordinate pair is applied
+	// and also when undoing an action like here.
+	if ((nc.y % 2) != 0)
+		nc.x = nc.x - 1;
+	map->normalize_coords(nc);
 	map->set_origin(nc);
 	eia.map_changed(EditorInteractive::MapWas::kGloballyMutated);
 	eia.map_view()->scroll_to_field(Widelands::Coords(0, 0), MapView::Transition::Jump);

=== modified file 'src/logic/map.cc'
--- src/logic/map.cc	2017-12-18 10:42:40 +0000
+++ src/logic/map.cc	2017-12-19 18:24:38 +0000
@@ -359,7 +359,8 @@
 		}
 	}
 	// Now that we restructured the fields, we just overwrite the old order
-	fields_.reset(new_field_order.release());
+	for (decltype(width_) ind = 0; ind < width_*height_; ind++)
+		fields_[ind] = new_field_order[ind];
 
 	//  Inform immovables and bobs about their new coordinates.
 	for (FCoords c(Coords(0, 0), fields_.get()); c.y < height_; ++c.y)


Follow ups