rsx: Fix rare crash in vertex program decompiler

- This whole decompiler mess needs a rewrite
This commit is contained in:
kd-11 2024-12-28 15:32:53 +03:00 committed by kd-11
parent cfc124fabf
commit 01fe39fbb9

View file

@ -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<int>(m_instr_count); i++)
{
lvl -= m_instructions[i].close_scopes;
if (lvl < 1) lvl = 1;
lvl = std::max<int>(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";