1. Place some water on the map
2. Add fish
3. Change the map origin
4. Hit the undo button twice
The underlying problem here is that undo stops working for all editor tools once the map origin changes. The other tools simply won't undo anything (or maybe undo something in the wrong location?)
==29319==ERROR: AddressSanitizer: heap-use-after-free on address 0x63300005a349 at pc 0x000000fb7e40 bp 0x7ffc300a1910 sp 0x7ffc300a1900
WRITE of size 1 at 0x63300005a349 thread T0
#0 0xfb7e3f in Widelands::Map::initialize_resources(Widelands::FCoords const&, unsigned char, unsigned char) /home/bratzbert/sources/widelands/asan/src/logic/map.cc:1819
#1 0xe2e2da in EditorSetResourcesTool::handle_undo_impl(Widelands::World const&, Widelands::NodeAndTriangle<Widelands::Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert/sources/widelands/asan/src/editor/tools/set_resources_tool.cc:75
#2 0xe23344 in EditorIncreaseResourcesTool::handle_undo_impl(Widelands::World const&, Widelands::NodeAndTriangle<Widelands::Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert/sources/widelands/asan/src/editor/tools/increase_resources_tool.cc:71
#3 0xe172dd in EditorTool::handle_undo(EditorTool::ToolIndex, Widelands::World const&, Widelands::NodeAndTriangle<Widelands::Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert/sources/widelands/asan/src/editor/tools/tool.h:70
#4 0xe1870e in EditorHistory::undo_action(Widelands::World const&) /home/bratzbert/sources/widelands/asan/src/editor/tools/history.cc:67
#5 0xdd2bc0 in operator() /home/bratzbert/sources/widelands/asan/src/editor/editorinteractive.cc:133
0x63300005a349 is located 23369 bytes inside of 106496-byte region [0x633000054800,0x63300006e800)
freed by thread T0 here:
#0 0x7fd14bcb1caa in operator delete[](void*) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99caa)
#1 0xfc3258 in std::default_delete<Widelands::Field []>::operator()(Widelands::Field*) const /usr/include/c++/5/bits/unique_ptr.h:119
#2 0xfbf642 in std::unique_ptr<Widelands::Field [], std::default_delete<Widelands::Field []> >::reset(Widelands::Field*) /usr/include/c++/5/bits/unique_ptr.h:581
#3 0xfb01dc in Widelands::Map::set_origin(Widelands::Coords const&) /home/bratzbert/sources/widelands/asan/src/logic/map.cc:362
#4 0xe2bd0f in EditorSetOriginTool::handle_click_impl(Widelands::World const&, Widelands::NodeAndTriangle<Widelands::Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert/sources/widelands/asan/src/editor/tools/set_origin_tool.cc:31
#5 0xe17123 in EditorTool::handle_click(EditorTool::ToolIndex, Widelands::World const&, Widelands::NodeAndTriangle<Widelands::Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert/sources/widelands/asan/src/editor/tools/tool.h:60
#6 0xe1900f in EditorHistory::do_action(EditorTool&, EditorTool::ToolIndex, Widelands::Map&, Widelands::World const&, Widelands::NodeAndTriangle<Widelands::Coords, Widelands::Coords> const&, EditorInteractive&, bool) /home/bratzbert/sources/widelands/asan/src/editor/tools/history.cc:119
#7 0xdd6834 in EditorInteractive::map_clicked(Widelands::NodeAndTriangle<Widelands::Coords, Widelands::Coords> const&, bool) /home/bratzbert/sources/widelands/asan/src/editor/editorinteractive.cc:241
#8 0xdd2dab in operator() /home/bratzbert/sources/widelands/asan/src/editor/editorinteractive.cc:150
To reproduce the bug with the resources tool:
1. Place some water on the map
2. Add fish
3. Change the map origin
4. Hit the undo button twice
The underlying problem here is that undo stops working for all editor tools once the map origin changes. The other tools simply won't undo anything (or maybe undo something in the wrong location?)
==29319==ERROR: AddressSanitizer: heap-use-after-free on address 0x63300005a349 at pc 0x000000fb7e40 bp 0x7ffc300a1910 sp 0x7ffc300a1900 :Map::initializ e_resources( Widelands: :FCoords const&, unsigned char, unsigned char) /home/bratzbert /sources/ widelands/ asan/src/ logic/map. cc:1819 cesTool: :handle_ undo_impl( Widelands: :World const&, Widelands: :NodeAndTriangl e<Widelands: :Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert /sources/ widelands/ asan/src/ editor/ tools/set_ resources_ tool.cc: 75 esourcesTool: :handle_ undo_impl( Widelands: :World const&, Widelands: :NodeAndTriangl e<Widelands: :Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert /sources/ widelands/ asan/src/ editor/ tools/increase_ resources_ tool.cc: 71 :handle_ undo(EditorTool ::ToolIndex, Widelands::World const&, Widelands: :NodeAndTriangl e<Widelands: :Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert /sources/ widelands/ asan/src/ editor/ tools/tool. h:70 :undo_action( Widelands: :World const&) /home/bratzbert /sources/ widelands/ asan/src/ editor/ tools/history. cc:67 /sources/ widelands/ asan/src/ editor/ editorinteracti ve.cc:133
WRITE of size 1 at 0x63300005a349 thread T0
#0 0xfb7e3f in Widelands:
#1 0xe2e2da in EditorSetResour
#2 0xe23344 in EditorIncreaseR
#3 0xe172dd in EditorTool:
#4 0xe1870e in EditorHistory:
#5 0xdd2bc0 in operator() /home/bratzbert
0x63300005a349 is located 23369 bytes inside of 106496-byte region [0x633000054800 ,0x63300006e800 ) x86_64- linux-gnu/ libasan. so.2+0x99caa) delete< Widelands: :Field []>::operator( )(Widelands: :Field* ) const /usr/include/ c++/5/bits/ unique_ ptr.h:119 ptr<Widelands: :Field [], std::default_ delete< Widelands: :Field []> >::reset( Widelands: :Field* ) /usr/include/ c++/5/bits/ unique_ ptr.h:581 :Map::set_ origin( Widelands: :Coords const&) /home/bratzbert /sources/ widelands/ asan/src/ logic/map. cc:362 Tool::handle_ click_impl( Widelands: :World const&, Widelands: :NodeAndTriangl e<Widelands: :Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert /sources/ widelands/ asan/src/ editor/ tools/set_ origin_ tool.cc: 31 :handle_ click(EditorToo l::ToolIndex, Widelands::World const&, Widelands: :NodeAndTriangl e<Widelands: :Coords, Widelands::Coords> const&, EditorInteractive&, EditorActionArgs*, Widelands::Map*) /home/bratzbert /sources/ widelands/ asan/src/ editor/ tools/tool. h:60 :do_action( EditorTool& , EditorTool: :ToolIndex, Widelands::Map&, Widelands::World const&, Widelands: :NodeAndTriangl e<Widelands: :Coords, Widelands::Coords> const&, EditorInteractive&, bool) /home/bratzbert /sources/ widelands/ asan/src/ editor/ tools/history. cc:119 ve::map_ clicked( Widelands: :NodeAndTriangl e<Widelands: :Coords, Widelands::Coords> const&, bool) /home/bratzbert /sources/ widelands/ asan/src/ editor/ editorinteracti ve.cc:241 /sources/ widelands/ asan/src/ editor/ editorinteracti ve.cc:150
freed by thread T0 here:
#0 0x7fd14bcb1caa in operator delete[](void*) (/usr/lib/
#1 0xfc3258 in std::default_
#2 0xfbf642 in std::unique_
#3 0xfb01dc in Widelands:
#4 0xe2bd0f in EditorSetOrigin
#5 0xe17123 in EditorTool:
#6 0xe1900f in EditorHistory:
#7 0xdd6834 in EditorInteracti
#8 0xdd2dab in operator() /home/bratzbert