From eddc6f7f4a63c02839e3f51160978179713b6bca Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 11 Apr 2023 00:24:59 -0500 Subject: [PATCH] fix(gx): correct off-by-one error when popping render states --- src/gx/CGxDevice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gx/CGxDevice.cpp b/src/gx/CGxDevice.cpp index d96376e..31b30b6 100644 --- a/src/gx/CGxDevice.cpp +++ b/src/gx/CGxDevice.cpp @@ -734,8 +734,11 @@ void CGxDevice::RsPop() { auto topOfStack = this->m_stackOffsets[this->m_stackOffsets.Count() - 1]; if (this->m_pushedStates.Count() > topOfStack) { - for (int32_t i = this->m_pushedStates.Count() - 1; i > topOfStack; i--) { - auto ps = &this->m_pushedStates[i]; + auto bottomOfStack = this->m_pushedStates.Count() - 1; + auto stackSize = this->m_pushedStates.Count() - topOfStack; + + for (uint32_t stackOffset = 0; stackOffset < stackSize; stackOffset++) { + auto ps = &this->m_pushedStates[bottomOfStack - stackOffset]; auto rs = &this->m_appRenderStates[ps->m_which]; if (!rs->m_dirty) {