Widelands crashes when ships can't move

Bug #1009504 reported by Andreas Breitschopp
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
New
Undecided
Andreas Breitschopp

Bug Description

If you have so many ships e. g. in a small sea that a ship tries to move, but it can't, because in every direction there is another ship already, Widelands crashes.

As there were no info in the file stdout.txt after the crash I ran Widelands in the debugger and found the reason for the bug myself.

In the function (file "ship.cc")
    void Ship::ship_update_idle(Game & game, Bob::State & state)
the array "dirs" is set to "3" for every array element in the described situation above.
=> "dirmax" is set to "3", too.
=> As a result the probability for moving in any direction (represented by the array "prob") is set to "0" for each direction.
=> As a result "totalprob" has the value "0" in the next line, which obviously is not a very good situation (devision by zero):
    unsigned int rnd = game.logic_rand() % totalprob;

I've attached a patch that fixes this issue.

Tags: crash ships
Revision history for this message
Andreas Breitschopp (ab-tools) wrote :
Changed in widelands:
assignee: nobody → Andreas Breitschopp (ab-tools)
Revision history for this message
Shevonar (shevonar) wrote :

This is a duplicate of bug #963963.

Thanks for providing a patch tough ;) Could you create a branch with your fix and propose it for merging? This is how it is usually done here (in Widelands).

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.