From 5cfac55e340d18cc811abe58d5d405397c16cd5f Mon Sep 17 00:00:00 2001 From: Brandon Arrendondo Date: Tue, 23 Jun 2026 20:19:42 -0400 Subject: [PATCH] [rlgl] Fix matrix stack overflow in rlPushMatrix() The RL_MAX_MATRIX_STACK_SIZE check logged an error but did not return, so RLGL.State.stack[stackCounter] = *currentMatrix still executed when the stack was full -- writing one element past stack[RL_MAX_MATRIX_STACK_SIZE] and corrupting the adjacent RLGL.State members (stackCounter, etc.). rlPopMatrix() already guards the symmetric underflow case; add the missing early return. --- src/rlgl.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rlgl.h b/src/rlgl.h index ed5e50fb1..8c529a4e0 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1237,7 +1237,11 @@ void rlMatrixMode(int mode) // Push the current matrix into RLGL.State.stack void rlPushMatrix(void) { - if (RLGL.State.stackCounter >= RL_MAX_MATRIX_STACK_SIZE) TRACELOG(RL_LOG_ERROR, "RLGL: Matrix stack overflow (RL_MAX_MATRIX_STACK_SIZE)"); + if (RLGL.State.stackCounter >= RL_MAX_MATRIX_STACK_SIZE) + { + TRACELOG(RL_LOG_ERROR, "RLGL: Matrix stack overflow (RL_MAX_MATRIX_STACK_SIZE)"); + return; + } if (RLGL.State.currentMatrixMode == RL_MODELVIEW) {