~weedfreak/widelands/Innkeeper_upgrade

« back to all changes in this revision

Viewing changes to src/editor/tools/set_origin_tool.cc

Merged lp:~widelands-dev/widelands/fix-bug-1735980-related-problems:
Fix heap use after free bug, and avoid immovables ending up in wrong positions when pressing undo/redo in editor

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
                                      EditorInteractive& eia,
41
41
                                      EditorActionArgs* /* args */,
42
42
                                      Widelands::Map* map) {
43
 
        Widelands::Coords nc(
44
 
           map->get_width() - 1 - center.node.x, map->get_height() - 1 - center.node.y);
 
43
        Widelands::Coords nc(map->get_width() - center.node.x, map->get_height() - center.node.y);
 
44
 
 
45
        // Because of the triangle design of map, y is changed by an odd number.
 
46
        // The x must be syncronized with the y when coordinate pair is applied
 
47
        // and also when undoing an action like here.
 
48
        if ((nc.y % 2) != 0) {
 
49
                nc.x = nc.x - 1;
 
50
        }
 
51
        map->normalize_coords(nc);
45
52
        map->set_origin(nc);
46
53
        eia.map_changed(EditorInteractive::MapWas::kGloballyMutated);
47
54
        eia.map_view()->scroll_to_field(Widelands::Coords(0, 0), MapView::Transition::Jump);