Merge pull request #1452 from marauder2k9-torque/MEMORY-MANAGER-REFACTOR

Memory Manager Refactor
This commit is contained in:
Brian Roberts 2025-05-12 15:31:06 -05:00 committed by GitHub
commit 6cda97867c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 581 additions and 1811 deletions

View file

@ -516,7 +516,12 @@ if (m##name##AssetId[index] != StringTable->EmptyString())\
else Con::warnf("Warning: %s::LOAD_SOUNDASSET_ARRAY(%s[%i])-%s", mClassName, m##name##AssetId[index], index, ImageAsset::getAssetErrstrn(assetState).c_str());\
}
#define assetEnumNameConcat(x,suff)(new std::string( x + std::string(#suff)))->c_str()
#define assetEnumNameConcat(x, suff) ([](const char* base) { \
String result = String(base) + #suff; \
char* ret = Con::getReturnBuffer(result.length() + 1); \
dStrcpy(ret, result.c_str(), result.length() + 1); \
return ret; \
})(x)
#define INITPERSISTFIELD_SOUNDASSET_ENUMED(name, enumType, maxValue, consoleClass, docs) \
for (U32 i = 0; i < maxValue; i++)\

View file

@ -114,29 +114,6 @@ namespace engineAPI
}
// The following are some tricks to make the memory leak checker run after global
// dtors have executed by placing some code in the termination segments.
#if defined( TORQUE_DEBUG ) && !defined( TORQUE_DISABLE_MEMORY_MANAGER )
#ifdef TORQUE_COMPILER_VISUALC
# pragma data_seg( ".CRT$XTU" )
static void* sCheckMemBeforeTermination = &Memory::ensureAllFreed;
# pragma data_seg()
#elif defined( TORQUE_COMPILER_GCC )
__attribute__ ( ( destructor ) ) static void _ensureAllFreed()
{
Memory::ensureAllFreed();
}
#endif
#endif
// Process a time event and update all sub-processes
void processTimeEvent(S32 elapsedTime)
{
@ -216,10 +193,6 @@ void StandardMainLoop::init()
gStartupTimer = PlatformTimer::create();
#endif
#ifdef TORQUE_DEBUG_GUARD
Memory::flagCurrentAllocs( Memory::FLAG_Global );
#endif
Platform::setMathControlStateKnown();
// Asserts should be created FIRST
@ -327,10 +300,6 @@ void StandardMainLoop::init()
// Hook in for UDP notification
Net::getPacketReceiveEvent().notify(GNet, &NetInterface::processPacketReceiveEvent);
#ifdef TORQUE_DEBUG_GUARD
Memory::flagCurrentAllocs( Memory::FLAG_Static );
#endif
}
void StandardMainLoop::shutdown()
@ -378,9 +347,6 @@ void StandardMainLoop::shutdown()
// asserts should be destroyed LAST
PlatformAssert::destroy();
#if defined( TORQUE_DEBUG ) && !defined( TORQUE_DISABLE_MEMORY_MANAGER )
Memory::validate();
#endif
}
void StandardMainLoop::preShutdown()

View file

@ -119,6 +119,18 @@ void AssetManager::onRemove()
mAssetTagsManifest->deleteObject();
}
purgeAssets();
for (auto itr = mDeclaredAssets.begin(); itr != mDeclaredAssets.end(); ++itr)
{
delete itr->value;
}
mDeclaredAssets.clear();
// Clear dependency graphs
mAssetDependsOn.clear();
mAssetIsDependedOn.clear();
// Call parent.
Parent::onRemove();
}

View file

@ -71,7 +71,7 @@ char* ConsoleValue::convertToBuffer() const
const char* ConsoleValue::getConsoleData() const
{
return Con::getData(ct->consoleType, ct->dataPtr, 0, ct->enumTable);
return Con::getData(type, dataPtr, 0, enumTable);
}
ConsoleDocFragment* ConsoleDocFragment::smFirst;
@ -427,20 +427,6 @@ void init()
smConsoleInput.notify(postConsoleInput);
}
//--------------------------------------
void shutdown()
{
AssertFatal(active == true, "Con::shutdown should only be called once.");
active = false;
smConsoleInput.remove(postConsoleInput);
consoleLogFile.close();
Namespace::shutdown();
AbstractClassRep::shutdown();
Compiler::freeConsoleParserList();
}
bool isActive()
{
@ -1201,10 +1187,10 @@ ConsoleValue _internalExecute(S32 argc, ConsoleValue argv[])
warnf(ConsoleLogEntry::Script, "%s: Unknown command.", funcName);
STR.clearFunctionOffset();
return std::move(ConsoleValue());
return (ConsoleValue());
}
return std::move(ent->execute(argc, argv, NULL));
return (ent->execute(argc, argv, NULL));
}
ConsoleValue execute(S32 argc, ConsoleValue argv[])
@ -1234,7 +1220,7 @@ ConsoleValue execute(S32 argc, const char *argv[])
ConsoleStackFrameSaver stackSaver;
stackSaver.save();
StringArrayToConsoleValueWrapper args(argc, argv);
return std::move(execute(args.count(), args));
return (execute(args.count(), args));
}
//------------------------------------------------------------------------------
@ -1243,12 +1229,12 @@ ConsoleValue execute(S32 argc, const char *argv[])
static ConsoleValue _internalExecute(SimObject *object, S32 argc, ConsoleValue argv[], bool thisCallOnly)
{
if (object == NULL)
return std::move(ConsoleValue());
return (ConsoleValue());
if(argc < 2)
{
STR.clearFunctionOffset();
return std::move(ConsoleValue());
return (ConsoleValue());
}
// [neo, 10/05/2007 - #3010]
@ -1276,7 +1262,7 @@ static ConsoleValue _internalExecute(SimObject *object, S32 argc, ConsoleValue a
{
//warnf(ConsoleLogEntry::Script, "%s: undefined for object '%s' - id %d", funcName, object->getName(), object->getId());
STR.clearFunctionOffset();
return std::move(ConsoleValue());
return (ConsoleValue());
}
const char* oldIdent = dStrdup(argv[1].getString());
@ -1284,7 +1270,7 @@ static ConsoleValue _internalExecute(SimObject *object, S32 argc, ConsoleValue a
// Twiddle %this argument
argv[1].setInt(ident);
ConsoleValue ret = std::move(ent->execute(argc, argv, object));
ConsoleValue ret = (ent->execute(argc, argv, object));
// Twiddle it back
argv[1].setString(oldIdent);
@ -1295,7 +1281,7 @@ static ConsoleValue _internalExecute(SimObject *object, S32 argc, ConsoleValue a
warnf(ConsoleLogEntry::Script, "Con::execute - %d has no namespace: %s", object->getId(), funcName);
STR.clearFunctionOffset();
return std::move(ConsoleValue());
return (ConsoleValue());
}
ConsoleValue execute(SimObject *object, S32 argc, ConsoleValue argv[], bool thisCallOnly)
@ -1303,7 +1289,7 @@ ConsoleValue execute(SimObject *object, S32 argc, ConsoleValue argv[], bool this
if(argc < 2)
{
STR.clearFunctionOffset();
return std::move(ConsoleValue());
return (ConsoleValue());
}
ConsoleStackFrameSaver stackSaver;
@ -1313,7 +1299,7 @@ ConsoleValue execute(SimObject *object, S32 argc, ConsoleValue argv[], bool this
{
if (isMainThread())
{
return std::move(_internalExecute(object, argc, argv, thisCallOnly));
return (_internalExecute(object, argc, argv, thisCallOnly));
}
else
{
@ -1325,7 +1311,7 @@ ConsoleValue execute(SimObject *object, S32 argc, ConsoleValue argv[], bool this
warnf(ConsoleLogEntry::Script, "Con::execute - %d has no namespace: %s", object->getId(), argv[0].getString());
STR.clearFunctionOffset();
return std::move(ConsoleValue());
return (ConsoleValue());
}
ConsoleValue execute(SimObject *object, S32 argc, const char *argv[], bool thisCallOnly)
@ -1333,7 +1319,7 @@ ConsoleValue execute(SimObject *object, S32 argc, const char *argv[], bool thisC
ConsoleStackFrameSaver stackSaver;
stackSaver.save();
StringArrayToConsoleValueWrapper args(argc, argv);
return std::move(execute(object, args.count(), args, thisCallOnly));
return (execute(object, args.count(), args, thisCallOnly));
}
inline ConsoleValue _executef(SimObject *obj, S32 checkArgc, S32 argc, ConsoleValue *argv)
@ -1341,7 +1327,7 @@ inline ConsoleValue _executef(SimObject *obj, S32 checkArgc, S32 argc, ConsoleVa
const U32 maxArg = 12;
AssertFatal(checkArgc == argc, "Incorrect arg count passed to Con::executef(SimObject*)");
AssertFatal(argc <= maxArg - 1, "Too many args passed to Con::_executef(SimObject*). Please update the function to handle more.");
return std::move(execute(obj, argc, argv));
return (execute(obj, argc, argv));
}
//------------------------------------------------------------------------------
@ -1350,7 +1336,7 @@ inline ConsoleValue _executef(S32 checkArgc, S32 argc, ConsoleValue *argv)
const U32 maxArg = 10;
AssertFatal(checkArgc == argc, "Incorrect arg count passed to Con::executef()");
AssertFatal(argc <= maxArg, "Too many args passed to Con::_executef(). Please update the function to handle more.");
return std::move(execute(argc, argv));
return (execute(argc, argv));
}
//------------------------------------------------------------------------------
@ -2110,6 +2096,23 @@ void ensureTrailingSlash(char* pDstPath, const char* pSrcPath, S32 dstSize)
pDstPath[trailIndex] = 0;
}
//--------------------------------------
void shutdown()
{
AssertFatal(active == true, "Con::shutdown should only be called once.");
active = false;
smConsoleInput.remove(postConsoleInput);
consoleLogFile.close();
Namespace::shutdown();
AbstractClassRep::shutdown();
Compiler::freeConsoleParserList();
gGlobalVars.reset();
PathExpandos.clear();
}
//-----------------------------------------------------------------------------
StringTableEntry getDSOPath(const char *scriptPath)
@ -2309,10 +2312,10 @@ ConsoleValue _BaseEngineConsoleCallbackHelper::_exec()
STR.clearFunctionOffset();
mArgc = mInitialArgc; // reset
return std::move(ConsoleValue());
return (ConsoleValue());
}
ConsoleValue returnValue = std::move(Con::_internalExecute( mArgc, mArgv ));
ConsoleValue returnValue = (Con::_internalExecute( mArgc, mArgv ));
mArgc = mInitialArgc; // reset args
return returnValue;
}
@ -2321,7 +2324,7 @@ ConsoleValue _BaseEngineConsoleCallbackHelper::_execLater(SimConsoleThreadExecEv
{
mArgc = mInitialArgc; // reset args
Sim::postEvent((SimObject*)Sim::getRootGroup(), evt, Sim::getCurrentTime());
return std::move(evt->getCB().waitForResult());
return (evt->getCB().waitForResult());
}
//------------------------------------------------------------------------------

View file

@ -37,6 +37,7 @@
#include "core/util/str.h"
#include "core/util/journal/journaledSignal.h"
#include "core/stringTable.h"
#include <iostream>
class SimObject;
class Namespace;
@ -119,6 +120,7 @@ typedef const char *StringTableEntry;
enum ConsoleValueType
{
cvNULL = -5,
cvInteger = -4,
cvFloat = -3,
cvString = -2,
@ -126,93 +128,109 @@ enum ConsoleValueType
cvConsoleValueType = 0
};
struct ConsoleValueConsoleType
{
S32 consoleType;
void* dataPtr;
EnumTable* enumTable;
};
class ConsoleValue
{
public:
#pragma warning( push )
#pragma warning( disable : 4201 ) // warning C4201: nonstandard extension used : nameless struct/union
union
{
F64 f;
S64 i;
char* s;
void* data;
ConsoleValueConsoleType* ct;
struct
{
F64 f;
S64 i;
char* s;
};
struct
{
void* dataPtr;
EnumTable* enumTable;
};
};
S32 type;
U32 bufferLen;
static DataChunker sConversionAllocator;
char* convertToBuffer() const;
TORQUE_FORCEINLINE bool hasAllocatedData() const
{
return (type == ConsoleValueType::cvString || isConsoleType()) && data != NULL;
}
const char* getConsoleData() const;
TORQUE_FORCEINLINE void cleanupData()
{
if (hasAllocatedData())
if (type <= cvString && bufferLen > 0)
{
dFree(data);
data = NULL;
}
}
TORQUE_FORCEINLINE void _move(ConsoleValue&& ref) noexcept
{
type = ref.type;
switch (ref.type)
{
case cvInteger:
i = ref.i;
break;
case cvFloat:
f = ref.f;
break;
case cvSTEntry:
TORQUE_CASE_FALLTHROUGH;
case cvString:
s = ref.s;
break;
default:
data = ref.data;
break;
dFree(s);
bufferLen = 0;
}
ref.data = NULL;
ref.setEmptyString();
s = const_cast<char*>(StringTable->EmptyString());
type = ConsoleValueType::cvNULL;
}
public:
ConsoleValue()
{
type = ConsoleValueType::cvSTEntry;
s = const_cast<char*>(StringTable->EmptyString());
bufferLen = 0;
}
ConsoleValue(ConsoleValue&& ref) noexcept
ConsoleValue(const ConsoleValue& ref)
{
_move(std::move(ref));
type = ConsoleValueType::cvSTEntry;
s = const_cast<char*>(StringTable->EmptyString());
bufferLen = 0;
switch (ref.type)
{
case cvNULL:
std::cout << "Ref already cleared!";
break;
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.type, ref.dataPtr, ref.enumTable);
break;
}
}
TORQUE_FORCEINLINE ConsoleValue& operator=(ConsoleValue&& ref) noexcept
ConsoleValue& operator=(const ConsoleValue& ref)
{
_move(std::move(ref));
switch (ref.type)
{
case cvNULL:
std::cout << "Ref already cleared!";
break;
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.type, ref.dataPtr, ref.enumTable);
break;
}
return *this;
}
ConsoleValue(const ConsoleValue&) = delete;
ConsoleValue& operator=(const ConsoleValue&) = delete;
TORQUE_FORCEINLINE ~ConsoleValue()
{
cleanupData();
@ -308,16 +326,19 @@ public:
type = ConsoleValueType::cvString;
s = (char*)dMalloc(static_cast<dsize_t>(len) + 1);
s = (char*)dMalloc(len + 1);
bufferLen = len + 1;
s[len] = '\0';
dStrcpy(s, val, static_cast<dsize_t>(len) + 1);
dStrcpy(s, val, len + 1);
}
TORQUE_FORCEINLINE void setStringRef(const char* ref, S32 len)
{
cleanupData();
type = ConsoleValueType::cvString;
s = const_cast<char*>(ref);
s = (char*)std::move(ref);
bufferLen = len;
}
TORQUE_FORCEINLINE void setBool(const bool val)
@ -331,7 +352,8 @@ public:
{
cleanupData();
type = ConsoleValueType::cvSTEntry;
s = const_cast<char*>(val);
s = (char*)std::move(val);
bufferLen = 0;
}
TORQUE_FORCEINLINE void setEmptyString()
@ -339,12 +361,13 @@ public:
setStringTableEntry(StringTable->EmptyString());
}
TORQUE_FORCEINLINE void setConsoleData(S32 consoleType, void* dataPtr, const EnumTable* enumTable)
TORQUE_FORCEINLINE void setConsoleData(S32 inConsoleType, void* inDataPtr, const EnumTable* inEnumTable)
{
cleanupData();
type = ConsoleValueType::cvConsoleValueType;
ct = new ConsoleValueConsoleType{ consoleType, dataPtr, const_cast<EnumTable*>(enumTable) };
}
type = inConsoleType;
dataPtr = inDataPtr;
enumTable = const_cast<EnumTable*>(inEnumTable);
};
TORQUE_FORCEINLINE S32 getType() const
{
@ -366,11 +389,11 @@ public:
return type >= ConsoleValueType::cvConsoleValueType;
}
TORQUE_FORCEINLINE ConsoleValueConsoleType* getConsoleType() const
TORQUE_FORCEINLINE S32 getConsoleType() const
{
if(type >= ConsoleValueType::cvConsoleValueType)
{
return ct;
return type;
}
else
{
@ -1022,7 +1045,7 @@ namespace Con
ConsoleValue executef(R r, ArgTs ...argTs)
{
_EngineConsoleExecCallbackHelper<R> callback(r);
return std::move(callback.template call<ConsoleValue>(argTs...));
return (callback.template call<ConsoleValue>(argTs...));
}
/// }
};

View file

@ -924,6 +924,12 @@ void Namespace::shutdown()
for (Namespace *walk = mNamespaceList; walk; walk = walk->mNext)
walk->~Namespace();
gNamespaceCache.clear();
mNamespaceList = nullptr;
mGlobalNamespace = nullptr;
mAllocator.freeBlocks();
}
void Namespace::trashCache()
@ -1153,11 +1159,11 @@ ConsoleValue Namespace::Entry::execute(S32 argc, ConsoleValue *argv, SimObject *
{
if (mFunctionOffset)
{
return std::move(mModule->exec(mFunctionOffset, argv[0].getString(), mNamespace, argc, argv, false, mPackage).value);
return (mModule->exec(mFunctionOffset, argv[0].getString(), mNamespace, argc, argv, false, mPackage).value);
}
else
{
return std::move(ConsoleValue());
return (ConsoleValue());
}
}
@ -1167,7 +1173,7 @@ ConsoleValue Namespace::Entry::execute(S32 argc, ConsoleValue *argv, SimObject *
if (mToolOnly && !Con::isCurrentScriptToolScript())
{
Con::errorf(ConsoleLogEntry::Script, "%s::%s - attempting to call tools only function from outside of tools", mNamespace->mName, mFunctionName);
return std::move(ConsoleValue());
return (ConsoleValue());
}
#endif
@ -1175,7 +1181,7 @@ ConsoleValue Namespace::Entry::execute(S32 argc, ConsoleValue *argv, SimObject *
{
Con::warnf(ConsoleLogEntry::Script, "%s::%s - wrong number of arguments. got %d, expected %d to %d", mNamespace->mName, mFunctionName, argc, mMinArgs, mMaxArgs);
Con::warnf(ConsoleLogEntry::Script, "usage: %s", mUsage);
return std::move(ConsoleValue());
return (ConsoleValue());
}
ConsoleValue result;

View file

@ -321,7 +321,7 @@ public:
void reset();
inline ConsoleValue getValue() { return std::move(value); }
inline ConsoleValue getValue() { return (value); }
inline U32 getIntValue()
{
@ -349,8 +349,7 @@ public:
if (value.isConsoleType())
{
const char* dptr = Con::getData(TypeS32, &val, 0);
ConsoleValueConsoleType* cvt = value.getConsoleType();
Con::setData(cvt->consoleType, cvt->dataPtr, 0, 1, &dptr, cvt->enumTable);
Con::setData(value.type, value.dataPtr, 0, 1, &dptr, value.enumTable);
}
else
{
@ -373,8 +372,7 @@ public:
if (value.isConsoleType())
{
const char* dptr = Con::getData(TypeF32, &val, 0);
ConsoleValueConsoleType* cvt = value.getConsoleType();
Con::setData(cvt->consoleType, cvt->dataPtr, 0, 1, &dptr, cvt->enumTable);
Con::setData(value.type, value.dataPtr, 0, 1, &dptr, value.enumTable);
}
else
{
@ -397,8 +395,7 @@ public:
if (value.isConsoleType())
{
ConsoleValueConsoleType* cvt = value.getConsoleType();
Con::setData(cvt->consoleType, cvt->dataPtr, 0, 1, &val, cvt->enumTable);
Con::setData(value.type, value.dataPtr, 0, 1, &val, value.enumTable);
}
else
{

View file

@ -286,6 +286,12 @@ void AbstractClassRep::shutdown()
// Release storage allocated to the class table.
for (auto walk = classLinkList; walk; walk = walk->nextClass)
{
walk->mFieldList.clear();
walk->mFieldList.compact(); // Important: frees the internal buffer
}
for (U32 group = 0; group < NetClassGroupsCount; group++)
for(U32 type = 0; type < NetClassTypesCount; type++)
if( classTable[ group ][ type ] )

View file

@ -705,7 +705,9 @@ public:
smPropertyTable = _smPropertyTable;
const_cast<EngineTypeInfo*>(mTypeInfo)->mPropertyTable = &_smPropertyTable;
// After we hand it off, immediately delete if safe:
delete[] props;
// Let the base finish up.
AbstractClassRep::init();
}

View file

@ -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)

View file

@ -148,7 +148,7 @@ static void dumpVariable( Stream& stream,
// Skip variables for which we can't decipher their type.
ConsoleBaseType* type = ConsoleBaseType::getType( entry->value.getConsoleType()->consoleType );
ConsoleBaseType* type = ConsoleBaseType::getType( entry->value.type );
if( !type )
{
Con::errorf( "Can't find type for variable '%s'", entry->name );

View file

@ -14,10 +14,10 @@ namespace Con
public:
EvalResult() {}
EvalResult(ConsoleValue&& pValue)
EvalResult(ConsoleValue pValue)
{
valid = true;
value = (ConsoleValue&&)pValue;
value = (pValue);
}
EvalResult(String errorMessage)

View file

@ -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);

View file

@ -116,7 +116,7 @@ ConsoleValue SimConsoleThreadExecCallback::waitForResult()
{
if(sem->acquire(true))
{
return std::move(retVal);
return (retVal);
}
return ConsoleValue();
@ -134,9 +134,9 @@ void SimConsoleThreadExecEvent::process(SimObject* object)
if (cb)
{
if (mOnObject)
cb->handleCallback(std::move(Con::execute(object, mArgc, mArgv)));
cb->handleCallback(Con::execute(object, mArgc, mArgv));
else
cb->handleCallback(std::move(Con::execute(mArgc, mArgv)));
cb->handleCallback(Con::execute(mArgc, mArgv));
}
else
{

View file

@ -3536,15 +3536,13 @@ DefineEngineMethod( SimObject, getDebugInfo, ArrayObject*, (),,
array->push_back( "Flag|CanSave", object->getCanSave() ? "true" : "false" );
#ifndef TORQUE_DISABLE_MEMORY_MANAGER
Memory::Info memInfo;
Memory::MemInfo memInfo;
Memory::getMemoryInfo( object, memInfo );
array->push_back( "Memory|AllocNumber", String::ToString( memInfo.mAllocNumber ) );
array->push_back( "Memory|AllocSize", String::ToString( memInfo.mAllocSize ) );
array->push_back( "Memory|AllocFile", memInfo.mFileName );
array->push_back( "Memory|AllocLine", String::ToString( memInfo.mLineNumber ) );
array->push_back( "Memory|IsGlobal", memInfo.mIsGlobal ? "true" : "false" );
array->push_back( "Memory|IsStatic", memInfo.mIsStatic ? "true" : "false" );
array->push_back( "Memory|AllocNumber", String::ToString( memInfo.allocId) );
array->push_back( "Memory|AllocSize", String::ToString( (U32)memInfo.size) );
array->push_back( "Memory|AllocFile", memInfo.file);
array->push_back( "Memory|AllocLine", String::ToString( memInfo.line) );
#endif
return array;

View file

@ -3363,7 +3363,7 @@ yyreport_syntax_error (const yypcontext_t *ctx)
output += String::ToString("%5s | %*s", "", loc->first_column, "^");
}
yyerror("%s",output.c_str());
yyerror("%s", output.c_str());
return ret;
}

View file

@ -668,7 +668,7 @@ Con::EvalResult CodeBlock::compileExec(StringTableEntry fileName, const char *in
Con::warnf(ConsoleLogEntry::General, "precompile size mismatch, precompile: %d compile: %d", codeSize, lastIp);
// repurpose argc as local register counter for global state
return std::move(exec(0, fileName, NULL, localRegisterCount, 0, noCalls, NULL, setFrame));
return (exec(0, fileName, NULL, localRegisterCount, 0, noCalls, NULL, setFrame));
}
//-------------------------------------------------------------------------

View file

@ -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));
}
//------------------------------------------------------------

View file

@ -269,8 +269,10 @@ U32 CompilerStringTable::addFloatString(F64 value)
void CompilerStringTable::reset()
{
list = NULL;
// Reset list and associated variables
list = nullptr;
totalLen = 0;
hashTable.clear(); // Clear the lookup table too
}
char *CompilerStringTable::build()

View file

@ -1,4 +1,4 @@
#ifndef _EVALSTATE_H
#ifndef _EVALSTATE_H
#define _EVALSTATE_H
#include "console/consoleInternal.h"
@ -83,7 +83,7 @@ public:
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);

View file

@ -39,7 +39,7 @@ namespace TorqueScript
fileName = StringTable->insert(fileName);
CodeBlock* newCodeBlock = new CodeBlock();
return std::move(newCodeBlock->compileExec(fileName, string, false, fileName ? -1 : 0));
return (newCodeBlock->compileExec(fileName, string, false, fileName ? -1 : 0));
}
Con::EvalResult TorqueScriptRuntime::evaluate(const char* script, S32 frame, bool echo, const char* fileName)

View file

@ -289,6 +289,11 @@ UTF8* createUTF8string( const UTF16* unistring)
return ret;
}
void UTF16ClearCache()
{
sgUTF16Cache.clear();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

View file

@ -66,6 +66,8 @@ UTF16* createUTF16string( const UTF8 *unistring);
UTF8* createUTF8string( const UTF16 *unistring);
void UTF16ClearCache();
//-----------------------------------------------------------------------------
/// Functions that convert buffers of unicode code points, into a provided buffer.
/// - These functions are useful for working on existing buffers.
@ -138,4 +140,4 @@ const UTF8* getNthCodepoint(const UTF8 *unistring, const U32 n);
bool chompUTF8BOM( const char *inString, char **outStringPtr );
bool isValidUTF8BOM( U8 bom[4] );
#endif // _UNICODE_H_
#endif // _UNICODE_H_

View file

@ -193,7 +193,7 @@ private:
{
Node* mNext;
Pair mPair;
Node(): mNext(0) {}
Node(): mNext(nullptr) {}
Node(Pair p,Node* n)
: mNext(n),
mPair(p)
@ -226,8 +226,8 @@ public:
_Iterator()
{
mHashTable = 0;
mLink = 0;
mHashTable = nullptr;
mLink = nullptr;
}
_Iterator(M* table,E* ptr)
@ -320,7 +320,7 @@ public:
template<typename Key, typename Value> HashTable<Key,Value>::HashTable() : mNodeAllocator(512)
{
mTableSize = 0;
mTable = 0;
mTable = nullptr;
mSize = 0;
}
@ -328,7 +328,7 @@ template<typename Key, typename Value> HashTable<Key,Value>::HashTable(const Has
{
mSize = 0;
mTableSize = 0;
mTable = 0;
mTable = nullptr;
*this = p;
}
@ -357,7 +357,7 @@ typename HashTable<Key,Value>::Node* HashTable<Key,Value>::_next(U32 index) cons
for (; index < mTableSize; index++)
if (Node* node = mTable[index])
return node;
return 0;
return nullptr;
}
template<typename Key, typename Value>
@ -402,7 +402,7 @@ void HashTable<Key,Value>::_destroy()
mNodeAllocator.freeBlocks();
delete[] mTable;
mTable = NULL;
mTable = nullptr;
}
@ -509,7 +509,7 @@ typename HashTable<Key,Value>::Iterator HashTable<Key,Value>::insertEqual(const
template<typename Key, typename Value>
void HashTable<Key,Value>::erase(const Key& key)
{
if (mTable==NULL)
if (mTable == nullptr)
return;
Node** prev = &mTable[_index(key)];
for (Node* itr = *prev; itr; prev = &itr->mNext, itr = itr->mNext)
@ -529,7 +529,7 @@ void HashTable<Key,Value>::erase(const Key& key)
template<typename Key, typename Value>
void HashTable<Key,Value>::erase(Iterator node)
{
if (mTable==NULL)
if (mTable == nullptr)
return;
Node** prev = &mTable[_index(node->key)];
for (Node* itr = *prev; itr; prev = &itr->mNext, itr = itr->mNext)
@ -547,7 +547,7 @@ void HashTable<Key,Value>::erase(Iterator node)
template<typename Key, typename Value>
void HashTable<Key,Value>::erase(const Key & key, const Value & value)
{
if (mTable==NULL)
if (mTable == nullptr)
return;
Node** prev = &mTable[_index(key)];
for (Node* itr = *prev; itr; prev = &itr->mNext, itr = itr->mNext)
@ -591,7 +591,7 @@ typename HashTable<Key,Value>::Iterator HashTable<Key,Value>::find(const Key& ke
for (Node* itr = mTable[_index(key)]; itr; itr = itr->mNext)
if ( KeyCmp::equals<Key>( itr->mPair.key, key ) )
return Iterator(this,itr);
return Iterator(this,0);
return Iterator(this, nullptr);
}
template<typename Key, typename Value>
@ -605,7 +605,7 @@ typename HashTable<Key,Value>::ConstIterator HashTable<Key,Value>::find(const Ke
return ConstIterator(this,itr);
}
}
return ConstIterator(this,0);
return ConstIterator(this, nullptr);
}
template<typename Key, typename Value>
@ -659,13 +659,13 @@ inline typename HashTable<Key,Value>::ConstIterator HashTable<Key,Value>::begin(
template<typename Key, typename Value>
inline typename HashTable<Key,Value>::Iterator HashTable<Key,Value>::end()
{
return Iterator(this,0);
return Iterator(this, nullptr);
}
template<typename Key, typename Value>
inline typename HashTable<Key,Value>::ConstIterator HashTable<Key,Value>::end() const
{
return ConstIterator(this,0);
return ConstIterator(this, nullptr);
}

View file

@ -205,6 +205,7 @@ int main(int argc, const char **argv)
#include "platform/platform.h"
#include "app/mainLoop.h"
#include "T3D/gameFunctions.h"
#include "platform/platformMemory.h"
#if defined(WIN32) || defined(_WIN32)
//tell switchable graphics supported systems that they need to use the beefier GPU
@ -230,8 +231,9 @@ S32 TorqueMain(S32 argc, const char **argv)
// argv = argvFake;
// }
// Memory::enableLogging("testMem.log");
// Memory::setBreakAlloc(104717);
#if defined( TORQUE_DEBUG ) && !defined(TORQUE_DISABLE_MEMORY_MANAGER)
Memory::init();
#endif
// Initialize the subsystems.
StandardMainLoop::init();
@ -254,6 +256,12 @@ S32 TorqueMain(S32 argc, const char **argv)
if( StandardMainLoop::requiresRestart() )
Platform::restartInstance();
#if defined( TORQUE_DEBUG ) && !defined( TORQUE_DISABLE_MEMORY_MANAGER )
Memory::shutdown();
#endif
// Return.
return StandardMainLoop::getReturnStatus();
}

File diff suppressed because it is too large Load diff

View file

@ -27,33 +27,25 @@
namespace Memory
{
enum EFlag
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
struct MemInfo
{
FLAG_Debug,
FLAG_Global,
FLAG_Static
void* ptr;
dsize_t size;
const char* file;
U32 line;
U32 allocId;
bool flagged;
void* backtracePtrs[16];
int backtraceSize;
};
struct Info
{
U32 mAllocNumber;
U32 mAllocSize;
const char* mFileName;
U32 mLineNumber;
bool mIsArray;
bool mIsGlobal;
bool mIsStatic;
};
void checkPtr( void* ptr );
void flagCurrentAllocs( EFlag flag = FLAG_Debug );
void ensureAllFreed();
void dumpUnflaggedAllocs(const char *file, EFlag flag = FLAG_Debug );
S32 countUnflaggedAllocs(const char *file, S32 *outUnflaggedRealloc = NULL, EFlag flag = FLAG_Debug );
dsize_t getMemoryUsed();
dsize_t getMemoryAllocated();
void getMemoryInfo( void* ptr, Info& info );
void validate();
void init();
void shutdown();
void getMemoryInfo(void* ptr, MemInfo& info);
void checkPtr(void* ptr);
#endif
}
#endif // _TORQUE_PLATFORM_PLATFORMMEMORY_H_

View file

@ -317,6 +317,8 @@ void Platform::shutdown()
GFXDevice::destroy();
WinConsole::destroy();
UTF16ClearCache();
}
extern bool LinkConsoleFunctions;

View file

@ -922,7 +922,7 @@ void SceneZoneSpaceManager::verifyState()
AssertFatal( mObjectZoneLists.containsBinItem(object->mZoneListHandle, zoneId), "SceneZoneSpaceManager::verifyState - Object doesn't have zone in list!");
#ifndef TORQUE_DISABLE_MEMORY_MANAGER
Memory::checkPtr( ref->object );
Memory::checkPtr( object );
#endif
}
}

View file

@ -32,7 +32,8 @@
inline ConsoleValue RunScript(const char* str)
{
return std::move(Con::evaluate(str, false, NULL).value);
auto conRes = Con::evaluate(str, false, NULL);
return conRes.value;
}
using ::testing::Matcher;

View file

@ -29,12 +29,23 @@
#include "ts/tsMaterialList.h"
#include "core/stream/fileStream.h"
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#ifdef new
#undef new
#endif
#endif
// assimp include files.
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/types.h>
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
# define _new new(__FILE__, __LINE__)
# define new _new
#endif
U32 AssimpAppMaterial::sDefaultMatNumber = 0;
String AppMaterial::cleanString(const String& str)

View file

@ -26,8 +26,20 @@
#ifndef _APPMATERIAL_H_
#include "ts/loader/appMaterial.h"
#endif
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#ifdef new
#undef new
#endif
#endif
#include <assimp/scene.h>
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
# define _new new(__FILE__, __LINE__)
# define new _new
#endif
class Material;
class AssimpAppMaterial : public AppMaterial

View file

@ -24,12 +24,24 @@
#include "ts/collada/colladaExtensions.h"
#include "ts/assimp/assimpAppMesh.h"
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#ifdef new
#undef new
#endif
#endif
// assimp include files.
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/types.h>
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
# define _new new(__FILE__, __LINE__)
# define new _new
#endif
bool AssimpAppMesh::fixedSizeEnabled = false;
S32 AssimpAppMesh::fixedSize = 2;

View file

@ -25,12 +25,25 @@
#include "ts/assimp/assimpAppNode.h"
#include "ts/assimp/assimpAppMesh.h"
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#ifdef new
#undef new
#endif
#endif
// assimp include files.
#include <assimp/cimport.h>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/types.h>
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
# define _new new(__FILE__, __LINE__)
# define new _new
#endif
aiAnimation* AssimpAppNode::sActiveSequence = NULL;
F32 AssimpAppNode::sTimeMultiplier = 1.0f;

View file

@ -33,11 +33,23 @@
#include "ts/collada/colladaExtensions.h"
#endif
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#ifdef new
#undef new
#endif
#endif
#ifndef AI_TYPES_H_INC
#include <assimp/types.h>
#endif
#include <assimp/scene.h>
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
# define _new new(__FILE__, __LINE__)
# define new _new
#endif
class AssimpAppMesh;
class AssimpAppNode : public AppNode

View file

@ -18,8 +18,20 @@
#include "ts/loader/appSequence.h"
#endif
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#ifdef new
#undef new
#endif
#endif
#include <assimp/scene.h>
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
# define _new new(__FILE__, __LINE__)
# define new _new
#endif
class AssimpAppSequence : public AppSequence
{
String mSequenceName;

View file

@ -51,6 +51,11 @@
#include "gfx/bitmap/gBitmap.h"
#include "gui/controls/guiTreeViewCtrl.h"
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
#ifdef new
#undef new
#endif
#endif
// assimp include files.
#include <assimp/cimport.h>
#include <assimp/scene.h>
@ -59,6 +64,12 @@
#include <assimp/config.h>
#include <exception>
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
# define _new new(__FILE__, __LINE__)
# define new _new
#endif
MODULE_BEGIN( AssimpShapeLoader )
MODULE_INIT_AFTER( ShapeLoader )
MODULE_INIT

View file

@ -55,6 +55,9 @@
/// Define me if you want to disable Torque memory manager.
#cmakedefine TORQUE_DISABLE_MEMORY_MANAGER
#ifndef TORQUE_ENABLE_ASSERTS // disable memory manager when in release build.
#define TORQUE_DISABLE_MEMORY_MANAGER
#endif
/// Define me if you want to disable the virtual mount system.
#cmakedefine TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM