Update console.h

This commit is contained in:
marauder2k7 2025-05-12 16:35:08 +01:00
parent 41c3f610be
commit 2207ae4a65

View file

@ -150,6 +150,7 @@ public:
}; };
S32 type; S32 type;
U32 bufferLen;
static DataChunker sConversionAllocator; static DataChunker sConversionAllocator;
@ -159,24 +160,27 @@ public:
TORQUE_FORCEINLINE void cleanupData() TORQUE_FORCEINLINE void cleanupData()
{ {
if (type == cvString) if (type <= cvString && bufferLen > 0)
{ {
if (s != StringTable->EmptyString()) dFree(s);
dFree(s); bufferLen = 0;
} }
s = const_cast<char*>(StringTable->EmptyString());
type = ConsoleValueType::cvNULL; type = ConsoleValueType::cvNULL;
} }
ConsoleValue() ConsoleValue()
{ {
type = ConsoleValueType::cvSTEntry; type = ConsoleValueType::cvSTEntry;
s = const_cast<char*>(StringTable->EmptyString()); s = const_cast<char*>(StringTable->EmptyString());
bufferLen = 0;
} }
ConsoleValue(const ConsoleValue& ref) ConsoleValue(const ConsoleValue& ref)
{ {
type = ConsoleValueType::cvSTEntry; type = ConsoleValueType::cvSTEntry;
s = const_cast<char*>(StringTable->EmptyString()); s = const_cast<char*>(StringTable->EmptyString());
bufferLen = 0;
switch (ref.type) switch (ref.type)
{ {
@ -317,11 +321,14 @@ public:
setEmptyString(); setEmptyString();
return; return;
} }
cleanupData(); cleanupData();
type = ConsoleValueType::cvString; type = ConsoleValueType::cvString;
s = (char*)dMalloc(len + 1); s = (char*)dMalloc(len + 1);
bufferLen = len + 1;
s[len] = '\0'; s[len] = '\0';
dStrcpy(s, val, len + 1); dStrcpy(s, val, len + 1);
} }
@ -342,7 +349,7 @@ public:
TORQUE_FORCEINLINE void setStringTableEntry(StringTableEntry val) TORQUE_FORCEINLINE void setStringTableEntry(StringTableEntry val)
{ {
//cleanupData(); cleanupData();
type = ConsoleValueType::cvSTEntry; type = ConsoleValueType::cvSTEntry;
s = const_cast<char*>(val); s = const_cast<char*>(val);
} }