From 8176145aaa974d50938cf95d432f8f2627661949 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Fri, 9 May 2025 08:47:34 +0100 Subject: [PATCH] remove more std::move std::move needs to be used with pointers, we werent doing that and so a temp var was being copied onto the heap when it should of stayed on the stack. This caused memory leaks --- Engine/source/console/console.h | 28 ------------------- Engine/source/console/consoleValueStack.h | 4 +-- Engine/source/console/runtime.h | 4 +-- Engine/source/console/script.h | 2 +- .../console/torquescript/compiledEval.cpp | 10 +++---- .../source/console/torquescript/evalState.h | 4 +-- 6 files changed, 12 insertions(+), 40 deletions(-) diff --git a/Engine/source/console/console.h b/Engine/source/console/console.h index d15cd801c..c00da4351 100644 --- a/Engine/source/console/console.h +++ b/Engine/source/console/console.h @@ -174,34 +174,6 @@ class ConsoleValue type = ConsoleValueType::cvNULL; } - TORQUE_FORCEINLINE void _move(ConsoleValue&& ref) noexcept - { - if (ref.type == ConsoleValueType::cvNULL) - { - std::cout << "Cannot Move a variable twice!"; - return; - } - switch (ref.type) - { - case cvInteger: - setInt(ref.i); - break; - case cvFloat: - setFloat(ref.f); - break; - case cvSTEntry: - setStringTableEntry(ref.s); - break; - case cvString: - setString(ref.s); - break; - default: - setConsoleData(ref.ct->consoleType, ref.ct->dataPtr, ref.ct->enumTable); - break; - } - ref.cleanupData(); - } - public: ConsoleValue() { diff --git a/Engine/source/console/consoleValueStack.h b/Engine/source/console/consoleValueStack.h index 8b44a652c..529f5f1a9 100644 --- a/Engine/source/console/consoleValueStack.h +++ b/Engine/source/console/consoleValueStack.h @@ -89,10 +89,10 @@ public: stack.pop_back(); } - TORQUE_FORCEINLINE void push(ConsoleValue&& val) + TORQUE_FORCEINLINE void push(ConsoleValue val) { Frame& frame = stack.last(); - frame.values[frame.internalCounter++] = std::move(val); + frame.values[frame.internalCounter++] = (val); } TORQUE_FORCEINLINE void argvc(StringTableEntry fn, S32& argc, ConsoleValue** argv) diff --git a/Engine/source/console/runtime.h b/Engine/source/console/runtime.h index 03d94ea85..cb2a32805 100644 --- a/Engine/source/console/runtime.h +++ b/Engine/source/console/runtime.h @@ -14,10 +14,10 @@ namespace Con public: EvalResult() {} - EvalResult(ConsoleValue&& pValue) + EvalResult(ConsoleValue pValue) { valid = true; - value = std::move(pValue); + value = (pValue); } EvalResult(String errorMessage) diff --git a/Engine/source/console/script.h b/Engine/source/console/script.h index 55653bff2..d6dca7c24 100644 --- a/Engine/source/console/script.h +++ b/Engine/source/console/script.h @@ -16,7 +16,7 @@ namespace Con gLastEvalResult.value.setString(pLastEvalResult.value.getString()); return pLastEvalResult; } - inline EvalResult getLastEvalResult() { return setLastEvalResult(std::move(gLastEvalResult)); }; + inline EvalResult getLastEvalResult() { return setLastEvalResult((gLastEvalResult)); }; bool runStream(Stream* byteCode, const char* fileName); diff --git a/Engine/source/console/torquescript/compiledEval.cpp b/Engine/source/console/torquescript/compiledEval.cpp index 94ddcab80..b9ada8750 100644 --- a/Engine/source/console/torquescript/compiledEval.cpp +++ b/Engine/source/console/torquescript/compiledEval.cpp @@ -612,7 +612,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi { S32 reg = code[ip + (2 + 6 + 1 + 1) + i]; ConsoleValue& value = argv[i + 1]; - Script::gEvalState.moveConsoleValue(reg, std::move(value)); + Script::gEvalState.moveConsoleValue(reg, (value)); } ip = ip + fnArgc + (2 + 6 + 1 + 1); curFloatTable = functionFloats; @@ -1214,7 +1214,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi case OP_RETURN: { - returnValue = std::move(stack[_STK]); + returnValue = (stack[_STK]); _STK--; // Clear iterator state. @@ -1905,7 +1905,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi if (nsEntry->mFunctionOffset) { ConsoleValue returnFromFn = nsEntry->mModule->exec(nsEntry->mFunctionOffset, fnName, nsEntry->mNamespace, callArgc, callArgv, false, nsEntry->mPackage).value; - stack[_STK + 1] = std::move(returnFromFn); + stack[_STK + 1] = (returnFromFn); } else // no body stack[_STK + 1].setEmptyString(); @@ -2040,7 +2040,7 @@ Con::EvalResult CodeBlock::exec(U32 ip, const char* functionName, Namespace* thi break; case OP_PUSH: - gCallStack.push(std::move(stack[_STK--])); + gCallStack.push((stack[_STK--])); break; case OP_PUSH_FRAME: @@ -2303,7 +2303,7 @@ execFinished: AssertFatal(!(_STK < stackStart), "String stack popped too much in script exec"); #endif - return Con::EvalResult(std::move(returnValue)); + return Con::EvalResult((returnValue)); } //------------------------------------------------------------ diff --git a/Engine/source/console/torquescript/evalState.h b/Engine/source/console/torquescript/evalState.h index 599af113e..05c3be335 100644 --- a/Engine/source/console/torquescript/evalState.h +++ b/Engine/source/console/torquescript/evalState.h @@ -81,9 +81,9 @@ public: currentRegisterArray->values[reg].setStringTableEntry(val); } - TORQUE_FORCEINLINE void moveConsoleValue(S32 reg, ConsoleValue&& val) + TORQUE_FORCEINLINE void moveConsoleValue(S32 reg, ConsoleValue val) { - currentRegisterArray->values[reg] = std::move(val); + currentRegisterArray->values[reg] = (val); } void pushFrame(StringTableEntry frameName, Namespace *ns, S32 regCount);