Widelands crashes when ships can't move
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_
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.
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).