Update console.h

This commit is contained in:
marauder2k7 2025-05-11 16:29:59 +01:00
parent 954c3b03db
commit 1ddc7219a5

View file

@ -137,13 +137,21 @@ struct ConsoleValueConsoleType
class ConsoleValue class ConsoleValue
{ {
#pragma warning( push )
#pragma warning( disable : 4201 ) // warning C4201: nonstandard extension used : nameless struct/union
union union
{ {
F64 f; struct
S64 i; {
char* s; F64 f;
void* data; S64 i;
ConsoleValueConsoleType* ct; char* s;
};
struct
{
ConsoleValueConsoleType* ct;
};
}; };
S32 type; S32 type;
@ -152,21 +160,11 @@ class ConsoleValue
char* convertToBuffer() const; char* convertToBuffer() const;
TORQUE_FORCEINLINE bool hasAllocatedData() const
{
return (isConsoleType() && data != NULL);
}
const char* getConsoleData() const; const char* getConsoleData() const;
TORQUE_FORCEINLINE void cleanupData() TORQUE_FORCEINLINE void cleanupData()
{ {
if (hasAllocatedData()) if (type == ConsoleValueType::cvString)
{
dFree(data);
data = NULL;
}
else if (type == ConsoleValueType::cvString)
{ {
if (s != StringTable->EmptyString()) if (s != StringTable->EmptyString())
dFree(s); dFree(s);
@ -323,8 +321,12 @@ public:
return; return;
} }
cleanupData(); cleanupData();
U32 oldLen = dStrlen(s);
type = ConsoleValueType::cvString; type = ConsoleValueType::cvString;
s = (char*)dMalloc(len + 1); s = (char*)dMalloc(len + 1);
s[len] = '\0'; s[len] = '\0';
dStrcpy(s, val, len + 1); dStrcpy(s, val, len + 1);
} }