Merge lp:~miroslavr256/widelands/bug-1550568-restool_undo_crash into lp:widelands

Proposed by Miroslav Remák
Status: Merged
Merged at revision: 7890
Proposed branch: lp:~miroslavr256/widelands/bug-1550568-restool_undo_crash
Merge into: lp:widelands
Diff against target: 36 lines (+6/-4)
2 files modified
src/editor/tools/editor_decrease_resources_tool.cc (+3/-2)
src/editor/tools/editor_increase_resources_tool.cc (+3/-2)
To merge this branch: bzr merge lp:~miroslavr256/widelands/bug-1550568-restool_undo_crash
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+289007@code.launchpad.net

Description of the change

The cause of this bug is dereferencing a past-the-end iterator in EditorSetResourcesTool::handle_undo_impl and setting a field's resource index to this undefined value.

In certain situations the 'increase/decrease resources' implementation can skip storing some of the old resource indices and amounts, which the undo implementation does not expect.

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

That fixed it, thanks!

@bunnybot merge

review: Approve
Revision history for this message
TiborB (tiborb95) wrote :

So if I understand it properly, even if the resource is not changed on particular field (like setting coal on grass), old (=new) resource is saved somewhere and when doing undo it is re-set (=replacing the resource with the very same resource).

Would it be reasonable to create another virtual resource like kNoChange and when doing undo particular field would be skipped, instead of reseting the value? I have performance in my mind. When I work on big maps it is real pain and editor lags very badly... I dont say that this here is a main culprit of course, but improvements in general are deserved

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 840. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/116045985.
Appveyor build 674. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_miroslavr256_widelands_bug_1550568_restool_undo_crash-674.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I think performance improvements are always a good idea. Go for it :)

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

@tiborb95

> So if I understand it properly, even if the resource is not changed on particular field (like
> setting coal on grass), old (=new) resource is saved somewhere and when doing undo it is re-set
> (=replacing the resource with the very same resource).

Yes, that's right.

> I have performance in my mind. When I work on big maps it is real pain and editor lags very badly...

I didn't really consider performance implications. My guess would be that the overlay update function is mostly at fault. Anyway, could you try this patch and see how it is performance-wise: http://pastie.org/private/cf2coofqafpffzm2h5ra ? This should skip unnecessary fields and still not crash the game after undoing the action.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Miroslav, you're now a member on widelands-dev, so we can work on branches together now :)

Could you please create a new branch + merge request?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/tools/editor_decrease_resources_tool.cc'
2--- src/editor/tools/editor_decrease_resources_tool.cc 2016-01-16 12:55:14 +0000
3+++ src/editor/tools/editor_decrease_resources_tool.cc 2016-03-15 05:03:53 +0000
4@@ -50,10 +50,11 @@
5 if (amount < 0)
6 amount = 0;
7
8+ args->orgResT.push_back(mr.location().field->get_resources());
9+ args->orgRes.push_back(mr.location().field->get_resources_amount());
10+
11 if (mr.location().field->get_resources() == args->cur_res &&
12 map->is_resource_valid(world, mr.location(), args->cur_res)) {
13- args->orgResT.push_back(mr.location().field->get_resources());
14- args->orgRes.push_back(mr.location().field->get_resources_amount());
15 map->initialize_resources(mr.location(), args->cur_res, amount);
16 }
17
18
19=== modified file 'src/editor/tools/editor_increase_resources_tool.cc'
20--- src/editor/tools/editor_increase_resources_tool.cc 2016-01-14 22:09:24 +0000
21+++ src/editor/tools/editor_increase_resources_tool.cc 2016-03-15 05:03:53 +0000
22@@ -47,11 +47,12 @@
23 if (amount > max_amount)
24 amount = max_amount;
25
26+ args->orgResT.push_back(mr.location().field->get_resources());
27+ args->orgRes.push_back(mr.location().field->get_resources_amount());
28+
29 if ((mr.location().field->get_resources() == args->cur_res ||
30 !mr.location().field->get_resources_amount()) &&
31 map->is_resource_valid(world, mr.location(), args->cur_res)) {
32- args->orgResT.push_back(mr.location().field->get_resources());
33- args->orgRes.push_back(mr.location().field->get_resources_amount());
34 map->initialize_resources(mr.location(), args->cur_res, amount);
35 }
36 } while (mr.advance(*map));

Subscribers

People subscribed via source and target branches

to status/vote changes: