Pārlūkot izejas kodu

Update console.h

marauder2k7 5 mēneši atpakaļ
vecāks
revīzija
2207ae4a65
1 mainītis faili ar 11 papildinājumiem un 4 dzēšanām
  1. 11 4
      Engine/source/console/console.h

+ 11 - 4
Engine/source/console/console.h

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