From cf4162d3fb93fd02ce83f65246cf05db7ea9087b Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 28 Dec 2024 15:32:53 +0300 Subject: [PATCH] rsx: Fix rare crash in vertex program decompiler - This whole decompiler mess needs a rewrite --- rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp b/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp index c5f8742be2..1511902300 100644 --- a/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/Program/VertexProgramDecompiler.cpp @@ -362,14 +362,13 @@ std::string VertexProgramDecompiler::NotZeroPositive(const std::string& code) std::string VertexProgramDecompiler::BuildCode() { std::string main_body; - for (uint i = 0, lvl = 1; i < m_instr_count; i++) + for (int i = 0, lvl = 1; i < static_cast(m_instr_count); i++) { - lvl -= m_instructions[i].close_scopes; - if (lvl < 1) lvl = 1; + lvl = std::max(lvl - m_instructions[i].close_scopes, 0); + for (int j = 0; j < m_instructions[i].put_close_scopes; ++j) { - --lvl; - if (lvl < 1) lvl = 1; + if (lvl > 1) --lvl; main_body.append(lvl, '\t') += "}\n"; } @@ -380,6 +379,8 @@ std::string VertexProgramDecompiler::BuildCode() lvl++; } + ensure(lvl >= 0); // Underflow of indent level will cause crashes!! + for (const auto& instruction_body : m_instructions[i].body) { main_body.append(lvl, '\t') += instruction_body + "\n";