Skip to content

Fix game crash when burndelay is 0 bug#179

Merged
TheAssassin merged 4 commits intomasterfrom
fix-burndelay-0-bug
Dec 5, 2020
Merged

Fix game crash when burndelay is 0 bug#179
TheAssassin merged 4 commits intomasterfrom
fix-burndelay-0-bug

Conversation

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

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

@MoonPadUSer
Copy link
Copy Markdown
Contributor Author

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

I just made PR #182 :)

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
Copy Markdown
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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@MoonPadUSer MoonPadUSer requested a review from TheAssassin August 2, 2020 13:51
Copy link
Copy Markdown
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