Editor remove resources does not work as expected

Bug #1570094 reported by kaputtnik
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
High
Unassigned

Bug Description

R7959
Steps to reproduce:

Start editor
Open Resource tool choose water and set Increase/Decrease to maximum (63)
Place resource
Use info tool on the same spot: It says there is Resource amount of 50
Choose the water resource again
Use Shift to remove the resource one time (because De/Increase is 63 the sign should disappear, but it don't)
Use the info tool on the same spot: It says Resource amount: 243
Choose the water resource again
Use Shift and click about 16 times on the resource you set before
The resource sign disappears
Click once again (with Shift)
The resource sign appears again
Use the info tool on the same spot: It says resource amount is 196

Related branches

Revision history for this message
kaputtnik (franku) wrote :

The culprit is in http://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/src/editor/tools/decrease_resources_tool.cc#L49

Subtracting a value to an unsigned int8 which is greater than the actual value results in uncommon behavior. The solution would be to depend the subtraction on the values:

if (amount < args->change_by) {
   amount = 0;
}
else
{
 amount -= args->change_by;
}

Something like that would solve this. Tomorrow i propose a branch ....

Revision history for this message
GunChleoc (gunchleoc) wrote :

Have a look at this line too:

http://bazaar.launchpad.net/~widelands-dev/widelands/bug-1545243-plnum-lua/revision/7846

Undo what I did there - that might be our general fix.

Search for if (amount < 0), there might be more occurrences of the problem.

GunChleoc (gunchleoc)
summary: - Editor remove resources does not work as aspected
+ Editor remove resources does not work as expected
Changed in widelands:
milestone: none → build19-rc1
importance: Undecided → High
assignee: nobody → kaputtnik (franku)
Revision history for this message
kaputtnik (franku) wrote :

Thanks, that looks good :-)

The compiler complains already about "amount < 0" because amount is unsigned int and couldn't be negative. But this warning is only shown when compiling from scratch or after clean up.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I actually messed that up when changing the datatypes. When I merged trunk into that branch, I had forgotten the reason for the changes and reverted them. Thanks for cleaning up after me :)

Changed in widelands:
status: New → Fix Committed
assignee: kaputtnik (franku) → nobody
GunChleoc (gunchleoc)
Changed in widelands:
status: Fix Committed → Fix Released
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build19-rc1.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.