Skip to content

[rlsw] Fix matrix stack underflow in swPopMatrix() - #6362

Merged
raysan5 merged 1 commit into
raysan5:masterfrom
shadye-6:fix-rlsw-matrix-underflow
Nov 8, 2026
Merged

raysan5 merged 1 commit into
raysan5:masterfrom
shadye-6:fix-rlsw-matrix-underflow

Conversation

@shadye-6

@shadye-6 shadye-6 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix matrix stack underflow in swPopMatrix() for all three matrix modes in src/external/rlsw.h. problem described in issue.

Closes #6361

Solution

changed the underflow checks for all three matrix stacks from <= 0 to <= 1, which prevents popping the initial matrix, sets SW_STACK_UNDERFLOW, and preserves the existing matrix stack state.

Testing

verified using a standalone rlsw test harness compiled with Clang 18.1.3, ASan and UBSan.

The matrix stack counters start at 1 for their initial matrices. Reject pops when the counter is <= 1 to prevent out-of-bounds access and correctly report SW_STACK_UNDERFLOW.
@shadye-6

shadye-6 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

hey @raysan5, just following up on this PR, it's a pretty small fix, could you pls review? thanks for your time.

@raysan5

raysan5 commented Nov 5, 2026

Copy link
Copy Markdown
Owner

@Bigfoot71 it looks good to me, despite the apparently AI generated issue, but please, could you take a second look to confirm merge?

@shadye-6

shadye-6 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

hi @raysan5 , just following up again on this PR, it's a very small patch, and i've rewritten the issue as well in simpler terms. please can you have a look again. thanks for your time.

@raysan5

raysan5 commented Nov 7, 2026

Copy link
Copy Markdown
Owner

@shadye-6 please, don't insist, PRs could take from weeks to months to be reviewed and merged, if merged. This is an open source project.

@Bigfoot71

Copy link
Copy Markdown
Contributor

@raysan5 Thanks for the ping, reviewed on my end, the fix is correct, it can be merged.


Related note, I just noticed that swGetIntegerv() doesn't return the matrix stack depths:

raylib/src/external/rlsw.h

Lines 4078 to 4088 in 985ac29

void swGetIntegerv(SWget name, int *v)
{
switch (name)
{
case SW_MODELVIEW_STACK_DEPTH: *v = SW_MODELVIEW_STACK_DEPTH; break;
case SW_PROJECTION_STACK_DEPTH: *v = SW_PROJECTION_STACK_DEPTH; break;
case SW_TEXTURE_STACK_DEPTH: *v = SW_TEXTURE_STACK_DEPTH; break;
case SW_DRAW_FRAMEBUFFER_BINDING: *v = RLSW.boundFramebufferId; break;
default: RLSW.errCode = SW_INVALID_ENUM; break;
}
}

It looks like a placeholder that was never completed, it should return the stack counter for each stack.
I can do another PR if you prefer.

@raysan5
raysan5 merged commit 55c9651 into raysan5:master Nov 8, 2026
@raysan5

raysan5 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

@Bigfoot71 thanks for the review! Merging!

I can do another PR if you prefer.

Yes, please.

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.

[rlsw] Fix matrix stack underflow in swPopMatrix()

3 participants