Skip to content
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

Merged
merged 4 commits into from
Dec 5, 2020
Merged

Conversation

MoonPadUSer
Copy link
Contributor

Setting the burndelay variable to 0 crashes the game. To fix this we can't just set burndelay min to 1 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

@MoonPadUSer MoonPadUSer added the bug Something isn't working label Jul 29, 2020
@voidanix
Copy link
Member

shockdelay suffers from the same issue, while you are at it consider taking a look there too

@MoonPadUSer
Copy link
Contributor Author

shockdelay suffers from the same issue, while you are at it consider taking a look there too

I just made PR #182 :)

@@ -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
Copy link
Member

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.

Suggested change
// 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

@@ -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);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to what?

Copy link
Contributor Author

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

Copy link
Member

@TheAssassin TheAssassin left a 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.

@TheAssassin TheAssassin merged commit fee5d1a into master Dec 5, 2020
@TheAssassin TheAssassin deleted the fix-burndelay-0-bug branch December 5, 2020 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

burndelay and shockdelay 0 causes game to crash
3 participants