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

rend2 - fixed out-of-bounds crash with weather #1190

Closed
wants to merge 3 commits into from
Closed

rend2 - fixed out-of-bounds crash with weather #1190

wants to merge 3 commits into from

Conversation

zen-v0
Copy link

@zen-v0 zen-v0 commented Nov 15, 2023

See issue #1189

The game will crash, if a map features weather (e.g. vjun1) and you noclip far enough beneath the map.

This was caused by an out-of-bounds exception caused by chunkIndex sometimes being negative.

@zen-v0 zen-v0 requested a review from a team as a code owner November 15, 2023 20:34
@zen-v0 zen-v0 changed the title rend2 - fixed out-of-bounds issue with weather rend2 - fixed out-of-bounds crash with weather Nov 15, 2023
@@ -1143,6 +1143,11 @@ void RB_SurfaceWeather( srfWeather_t *surf )
{
chunkIndex = (int(centerZoneOffsetX + numMinZonesX) + x + 1) % 3;
chunkIndex += (int(centerZoneOffsetY + numMinZonesY) + y + 1) % 3 * 3;

if (chunkIndex < 0) {
chunkIndex *= -1;
Copy link

@Charlese2 Charlese2 Nov 22, 2023

Choose a reason for hiding this comment

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

Because the % operator in C++ uses truncated division just flipping the sign won't lead to a continuous remainder.
image
With just flipping the sign, it causes clumping of the rain in the shader.
image

Copy link
Author

@zen-v0 zen-v0 Nov 23, 2023

Choose a reason for hiding this comment

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

Oh, yeah! You are right. I flew around and I didn't spot that issue on vjun1, but it's obvious on your screenshot.

I am not a math crack sadly, but offsetting negative indices with += array-size should theoretically work better shouldn't it?

Copy link
Member

Choose a reason for hiding this comment

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

I do not know if flipping the sign is actually the best fix all together either, but I could be wrong.

@zen-v0 zen-v0 closed this by deleting the head repository Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants