-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix game crash when burndelay is 0 bug #179
Conversation
|
I just made PR #182 :) |
src/game/game.cpp
Outdated
@@ -935,10 +935,12 @@ namespace game | |||
int millis = lastmillis-d->lastres[WR_BURN]; | |||
size_t seed = size_t(d) + (millis/50); | |||
float pc = 1, amt = (millis%50)/50.0f, intensity = 0.75f+(detrnd(seed, 25)*(1-amt) + detrnd(seed + 1, 25)*amt)/100.f; | |||
if(burntime-millis < burndelay) pc *= float(burntime-millis)/float(burndelay); | |||
// When playing on servers with an older version, burndelay can be 0, thus add a check to prevent division by 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is very long, and this is not a check you just enforce a lower boundary.
// When playing on servers with an older version, burndelay can be 0, thus add a check to prevent division by 0 | |
// avoid division by zero by enforcing new lower boundary |
src/game/game.cpp
Outdated
@@ -935,10 +935,12 @@ namespace game | |||
int millis = lastmillis-d->lastres[WR_BURN]; | |||
size_t seed = size_t(d) + (millis/50); | |||
float pc = 1, amt = (millis%50)/50.0f, intensity = 0.75f+(detrnd(seed, 25)*(1-amt) + detrnd(seed + 1, 25)*amt)/100.f; | |||
if(burntime-millis < burndelay) pc *= float(burntime-millis)/float(burndelay); | |||
// When playing on servers with an older version, burndelay can be 0, thus add a check to prevent division by 0 | |||
int _burndelay = std::max(burndelay, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _
prefix is preserved for standard-specified things (as per the ISO C standard) IIRC. Please rename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, changed them to fixed_burndelay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding more blank lines in the future, especially above inline comments. That really improves the code's readability.
Setting the
burndelay
variable to0
crashes the game. To fix this we can't just setburndelay
min to1
because servers that don't have the patch, will just override it, therefore I had to use temp vars like_burndelay = std::max(burndelay, 1);
Closes: #177