Merge lp:~widelands-dev/widelands/bug-1573968-new-map-crash into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7987
Proposed branch: lp:~widelands-dev/widelands/bug-1573968-new-map-crash
Merge into: lp:widelands
Diff against target: 103 lines (+23/-10)
5 files modified
src/editor/editorinteractive.cc (+11/-3)
src/editor/editorinteractive.h (+1/-0)
src/editor/tools/set_starting_pos_tool.cc (+9/-5)
src/editor/ui_menus/main_menu_new_map.cc (+1/-1)
src/editor/ui_menus/main_menu_random_map.cc (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1573968-new-map-crash
Reviewer Review Type Date Requested Status
kaputtnik (community) testing Approve
Review via email: mp+292712@code.launchpad.net

Commit message

Select info tool before creating new maps. This fixes a crash with the player tool.

To post a comment you must log in.
Revision history for this message
kaputtnik (franku) wrote :

Now i get a crash when

1. Start editor
2. Place a player
3. Save the map
4. Load the previous saved map

Result:
widelands: /home/kaputtnik/widelands-repo/bug-1573968-new-map-crash/src/logic/map.h:205: Widelands::Coords Widelands::Map::get_starting_pos(Widelands::PlayerNumber) const: Zusicherung »1 <= p && p <= get_nrplayers()« nicht erfüllt.

review: Needs Fixing
Revision history for this message
GunChleoc (gunchleoc) wrote :

Oops, should be fixed now.

Revision history for this message
kaputtnik (franku) wrote :

I got other crashs of the same type, but couldn't reproduce it with explicit steps. Sometimes with the steps described earlier, sometimes when a map was loaded and then a new map is created ... feels randomly :-(

Are there no initial data for the editor to which it can be reset before a map is loaded or a new map is going to be created? It looks always that there is some data from the previous map when creating a new map or loading a map...

review: Needs Fixing
Revision history for this message
kaputtnik (franku) wrote :

I think it's the buildhelp overlay what's causing this. I can reproduce this now as follows:

1. Start editor
2. Deactivate buildhelp
3. Place player (the buildhelp should normally be activated, but it isn't)
4. Save map
5. Load previous saved map

Crash.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1054. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/125345011.
Appveyor build 885. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1573968_new_map_crash-885.

Revision history for this message
GunChleoc (gunchleoc) wrote :

> Are there no initial data for the editor to which it can be reset before a map
> is loaded or a new map is going to be created? It looks always that there is
> some data from the previous map when creating a new map or loading a map...

There is already a TODO comment in the codebase for that. I am thinking of starting the next release cycle by going through TODO comments to clean stuff up.

I can't reproduce the crash now (maybe it doesn't happen often enough), but I have now added the same fix when loading a map. I think that should take care of it.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1063. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/125501343.
Appveyor build 894. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1573968_new_map_crash-894.

Revision history for this message
kaputtnik (franku) wrote :

I think it works now :-)

review: Approve (testing)
Revision history for this message
Miroslav Remák (miroslavr256) wrote :

I think selecting info tool in EditorInteractive::cleanup_for_load is unnecessary and does not fix the problem at its root. I propose:
 - changing 'current_player_ = 0;' to 'current_player_ = 1;' in EditorSetStartingPosTool's constructor
 - replacing 'select_tool(tools()->info, EditorTool::First);' with 'mutable_field_overlay_manager()->register_overlay_callback_function(nullptr);' in EditorInteractive::cleanup_for_load

Revision history for this message
GunChleoc (gunchleoc) wrote :

I like that much better, thank you!

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/editorinteractive.cc'
2--- src/editor/editorinteractive.cc 2016-04-14 16:23:39 +0000
3+++ src/editor/editorinteractive.cc 2016-05-04 06:29:55 +0000
4@@ -214,9 +214,7 @@
5
6 Widelands::Map & map = egbase().map();
7
8- // TODO(unknown): get rid of cleanup_for_load, it tends to be very messy
9- // Instead, delete and re-create the egbase.
10- egbase().cleanup_for_load();
11+ cleanup_for_load();
12
13 std::unique_ptr<Widelands::MapLoader> ml(map.get_correct_loader(filename));
14 if (!ml.get())
15@@ -245,6 +243,16 @@
16 map_changed(MapWas::kReplaced);
17 }
18
19+void EditorInteractive::cleanup_for_load()
20+{
21+ // TODO(unknown): get rid of cleanup_for_load, it tends to be very messy
22+ // Instead, delete and re-create the egbase.
23+ egbase().cleanup_for_load();
24+
25+ // Select a tool that doesn't care about map changes
26+ mutable_field_overlay_manager()->register_overlay_callback_function(nullptr);
27+}
28+
29
30 /// Called just before the editor starts, after postload, init and gfxload.
31 void EditorInteractive::start() {
32
33=== modified file 'src/editor/editorinteractive.h'
34--- src/editor/editorinteractive.h 2016-04-14 16:23:39 +0000
35+++ src/editor/editorinteractive.h 2016-05-04 06:29:55 +0000
36@@ -92,6 +92,7 @@
37 static void run_editor(const std::string & filename, const std::string& script_to_run);
38
39 void load(const std::string & filename);
40+ void cleanup_for_load() override;
41
42 // leaf functions from base class
43 void start() override;
44
45=== modified file 'src/editor/tools/set_starting_pos_tool.cc'
46--- src/editor/tools/set_starting_pos_tool.cc 2016-04-06 09:23:04 +0000
47+++ src/editor/tools/set_starting_pos_tool.cc 2016-05-04 06:29:55 +0000
48@@ -60,12 +60,16 @@
49 // Area around already placed players
50 Widelands::PlayerNumber const nr_players = map.get_nrplayers();
51 for (Widelands::PlayerNumber p = 1, last = current_player_ - 1;; ++p) {
52- for (; p <= last; ++p)
53- if (Widelands::Coords const sp = map.get_starting_pos(p))
54- if (map.calc_distance(sp, c) < MIN_PLACE_AROUND_PLAYERS)
55+ for (; p <= last; ++p) {
56+ if (Widelands::Coords const sp = map.get_starting_pos(p)) {
57+ if (map.calc_distance(sp, c) < MIN_PLACE_AROUND_PLAYERS) {
58 return 0;
59- if (last == nr_players)
60+ }
61+ }
62+ }
63+ if (last == nr_players) {
64 break;
65+ }
66 last = nr_players;
67 }
68
69@@ -80,7 +84,7 @@
70 EditorSetStartingPosTool::EditorSetStartingPosTool()
71 : EditorTool(*this, *this, false), current_sel_pic_(nullptr)
72 {
73- current_player_ = 0;
74+ current_player_ = 1;
75 fsel_picsname_ = "images/players/fsel_editor_set_player_01_pos.png";
76 }
77
78
79=== modified file 'src/editor/ui_menus/main_menu_new_map.cc'
80--- src/editor/ui_menus/main_menu_new_map.cc 2016-04-06 09:23:04 +0000
81+++ src/editor/ui_menus/main_menu_new_map.cc 2016-05-04 06:29:55 +0000
82@@ -121,7 +121,7 @@
83
84 loader_ui.step(_("Creating empty map…"));
85
86- egbase.cleanup_for_load();
87+ parent.cleanup_for_load();
88
89 map.create_empty_map(
90 egbase.world(),
91
92=== modified file 'src/editor/ui_menus/main_menu_random_map.cc'
93--- src/editor/ui_menus/main_menu_random_map.cc 2016-04-23 13:33:53 +0000
94+++ src/editor/ui_menus/main_menu_random_map.cc 2016-05-04 06:29:55 +0000
95@@ -432,7 +432,7 @@
96 Widelands::Map & map = egbase.map();
97 UI::ProgressWindow loader_ui;
98
99- egbase.cleanup_for_load();
100+ eia.cleanup_for_load();
101
102 UniqueRandomMapInfo map_info;
103 set_map_info(map_info);

Subscribers

People subscribed via source and target branches

to status/vote changes: