Merge lp:~widelands-dev/widelands/bug-1818494-reset-zoom-crash into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 9011
Proposed branch: lp:~widelands-dev/widelands/bug-1818494-reset-zoom-crash
Merge into: lp:widelands
Diff against target: 48 lines (+19/-1)
2 files modified
src/editor/tools/history.cc (+8/-0)
src/graphic/gl/fields_to_draw.cc (+11/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1818494-reset-zoom-crash
Reviewer Review Type Date Requested Status
Klaus Halfmann code reieww, compile, testing Approve
Review via email: mp+364208@code.launchpad.net

Commit message

Fix/catch some memory issues
- Limit the editor undo stack to 500 items
- In fields_to_draw, make sure not to resize the vector to more memory than available,
  because this can crash when zooming out.
  Simply skip the unavailable bottom fields when drawing and log it.

Description of the change

This should help with a crash that a user experienced when using the editor for a long time or playing long games, then zooming out.

The problem is that Widelands doesn't have enough memory allocated to grow the vector to the required size in fields_to_draw.reset(). So, I have added a safeguard there which will log to console when there isn't enough memory and then simply not update the additional fields. The user will see fields not properly drawn/updated at the bottom of the screen then.

The problem happens only after a long time -> I found that the editor's "Undo" stack is unlimited, so I have putting an arbitrary cap on that.

No solution for the in-game memory consumption yet. We do have steadily growing containers there which are the statistics, but that can't be helped. There might be others that we haven't found yet though.

To post a comment you must log in.
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Wow, we should get the Map(s) this user created :-)

To reproduce the first problem we should edit the biggest maxium possible
map with as many objects a possible and zomm out and in like mad.
Never restart to get the overflow in that undo stack?.

An in a normal game this could happen, too?

Can we perhaps limit the maximum Zoom-factor to avoid this?

Some questions / comments inline.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Found a (related?) Bug at #1819311 before I coould do the > 500 undos :-)

OTOH from the code review it sould not harm.

I will do more tests with this huge (nice) map, lets see what we will find.

review: Approve (code reieww, compile, testing)
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4574. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/504234539.
Appveyor build 4361. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1818494_reset_zoom_crash-4361.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review!

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/tools/history.cc'
2--- src/editor/tools/history.cc 2019-02-23 11:00:49 +0000
3+++ src/editor/tools/history.cc 2019-03-10 07:49:40 +0000
4@@ -27,6 +27,9 @@
5
6 // === EditorActionArgs === //
7
8+constexpr size_t kMaximumUndoActions = 500;
9+constexpr size_t kTooManyUndoActionsDeleteBatch = 50;
10+
11 EditorActionArgs::EditorActionArgs(EditorInteractive& base)
12 : sel_radius(base.get_sel_radius()),
13 change_by(0),
14@@ -115,6 +118,11 @@
15 undo_stack_.push_front(ac);
16 undo_button_.set_enabled(true);
17 redo_button_.set_enabled(false);
18+ if (undo_stack_.size() > kMaximumUndoActions) {
19+ for (size_t i = 0; i < kTooManyUndoActionsDeleteBatch; ++i) {
20+ undo_stack_.pop_back();
21+ }
22+ }
23 }
24 return tool.handle_click(ind, world, center, parent, ac.args, &map);
25 }
26
27=== modified file 'src/graphic/gl/fields_to_draw.cc'
28--- src/graphic/gl/fields_to_draw.cc 2019-02-23 11:00:49 +0000
29+++ src/graphic/gl/fields_to_draw.cc 2019-03-10 07:49:40 +0000
30@@ -106,7 +106,17 @@
31
32 w_ = max_fx_ - min_fx_ + 1;
33 h_ = max_fy_ - min_fy_ + 1;
34- const size_t dimension = w_ * h_;
35+ assert(w_ > 0);
36+ assert(h_ > 0);
37+
38+ // Ensure that there is enough memory for the resize operation
39+ size_t dimension = w_ * h_;
40+ const size_t max_dimension = fields_.max_size();
41+ if (dimension > max_dimension) {
42+ log("WARNING: Not enough memory allocated to redraw the whole map!\nWe recommend that you restart Widelands\n");
43+ dimension = max_dimension;
44+ }
45+ // Now resize the vector
46 if (fields_.size() != dimension) {
47 fields_.resize(dimension);
48 }

Subscribers

People subscribed via source and target branches

to status/vote changes: