diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index c0dd7db916..6cada2d36e 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -11358,6 +11358,9 @@ ExpEmit FxLocalVariableDeclaration::Emit(VMFunctionBuilder *build) auto& registers = build->Registers[regType]; RegNum = registers.Get(RegCount); + // Check for reused registers and clean them if needed + bool useDirtyRegisters = false; + for (int reg = RegNum, end = RegNum + RegCount; reg < end; ++reg) { if (!registers.IsDirty(reg)) @@ -11365,7 +11368,7 @@ ExpEmit FxLocalVariableDeclaration::Emit(VMFunctionBuilder *build) continue; } - ScriptPosition.Message(MSG_DEBUGMSG, "Implicit initialization of variable %s\n", Name.GetChars()); + useDirtyRegisters = true; switch (regType) { @@ -11390,6 +11393,11 @@ ExpEmit FxLocalVariableDeclaration::Emit(VMFunctionBuilder *build) break; } } + + if (useDirtyRegisters) + { + ScriptPosition.Message(MSG_DEBUGMSG, "Implicit initialization of variable %s", Name.GetChars()); + } } else {