Kaynağa Gözat

Merge pull request #413 from blackberry-gaming/next-ablake

Next ablake: Memory leaks, DebugMem error reporting.
Sean Paul Taylor 13 yıl önce
ebeveyn
işleme
91103a3dc0
3 değiştirilmiş dosya ile 24 ekleme ve 14 silme
  1. 10 10
      gameplay/src/DebugNew.cpp
  2. 4 4
      gameplay/src/Ref.cpp
  3. 10 0
      gameplay/src/Theme.cpp

+ 10 - 10
gameplay/src/DebugNew.cpp

@@ -122,7 +122,7 @@ void* debugAlloc(std::size_t size, const char* file, int line)
         if (!initialized)
         {
             if (!SymInitialize(GetCurrentProcess(), NULL, true))
-                gameplay::printError("Stack trace tracking will not work.");
+                gameplay::printError("Stack trace tracking will not work.\n");
             initialized = true;
         }
     
@@ -181,7 +181,7 @@ void debugFree(void* p)
     // Sanity check: ensure that address in record matches passed in address
     if (rec->address != (unsigned long)p)
     {
-        gameplay::printError("[memory] CORRUPTION: Attempting to free memory address with invalid memory allocation record.");
+        gameplay::printError("[memory] CORRUPTION: Attempting to free memory address with invalid memory allocation record.\n");
         return;
     }
 
@@ -221,7 +221,7 @@ void printStackTrace(MemoryAllocationRecord* rec)
         symbol->MaxNameLength = bufferSize;
         if (!SymGetSymFromAddr64(GetCurrentProcess(), pc, &displacement, symbol))
         {
-            gameplay::printError("[memory] STACK TRACE: <unknown location>");
+            gameplay::printError("[memory] STACK TRACE: <unknown location>\n");
         }
         else
         {
@@ -243,7 +243,7 @@ void printStackTrace(MemoryAllocationRecord* rec)
                     line.SizeOfStruct = sizeof(line);
                     if (!SymGetLineFromAddr64(GetCurrentProcess(), pc, &displacement, &line))
                     {
-                        gameplay::printError("[memory] STACK TRACE: %s - <unknown file>:<unknown line number>", symbol->Name);
+                        gameplay::printError("[memory] STACK TRACE: %s - <unknown file>:<unknown line number>\n", symbol->Name);
                     }
                     else
                     {
@@ -253,7 +253,7 @@ void printStackTrace(MemoryAllocationRecord* rec)
                         else
                             file++;
                         
-                        gameplay::printError("[memory] STACK TRACE: %s - %s:%d", symbol->Name, file, line.LineNumber);
+                        gameplay::printError("[memory] STACK TRACE: %s - %s:%d\n", symbol->Name, file, line.LineNumber);
                     }
                 }
             }
@@ -267,24 +267,24 @@ extern void printMemoryLeaks()
     // Dump general heap memory leaks
     if (__memoryAllocationCount == 0)
     {
-        gameplay::printError("[memory] All HEAP allocations successfully cleaned up (no leaks detected).");
+        gameplay::printError("[memory] All HEAP allocations successfully cleaned up (no leaks detected).\n");
     }
     else
     {
-        gameplay::printError("[memory] WARNING: %d HEAP allocations still active in memory.", __memoryAllocationCount);
+        gameplay::printError("[memory] WARNING: %d HEAP allocations still active in memory.\n", __memoryAllocationCount);
         MemoryAllocationRecord* rec = __memoryAllocations;
         while (rec)
         {
 #ifdef WIN32
             if (rec->trackStackTrace)
             {
-                gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d:", rec->address, rec->size);
+                gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d:\n", rec->address, rec->size);
                 printStackTrace(rec);
             }
             else
-                gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.", rec->address, rec->size, rec->line, rec->file);
+                gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
 #else
-            gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.", rec->address, rec->size, rec->line, rec->file);
+            gameplay::printError("[memory] LEAK: HEAP allocation leak at address %#x of size %d from line %d in file '%s'.\n", rec->address, rec->size, rec->line, rec->file);
 #endif
             rec = rec->next;
         }

+ 4 - 4
gameplay/src/Ref.cpp

@@ -68,16 +68,16 @@ void Ref::printLeaks()
     // Dump Ref object memory leaks
     if (__refAllocationCount == 0)
     {
-        printError("[memory] All Ref objects successfully cleaned up (no leaks detected).");
+        printError("[memory] All Ref objects successfully cleaned up (no leaks detected).\n");
     }
     else
     {
-        printError("[memory] WARNING: %d Ref objects still active in memory.", __refAllocationCount);
+        printError("[memory] WARNING: %d Ref objects still active in memory.\n", __refAllocationCount);
         for (RefAllocationRecord* rec = __refAllocations; rec != NULL; rec = rec->next)
         {
             Ref* ref = rec->ref;
             const char* type = typeid(*ref).name();
-            printError("[memory] LEAK: Ref object '%s' still active with reference count %d.", (type ? type : ""), ref->getRefCount());
+            printError("[memory] LEAK: Ref object '%s' still active with reference count %d.\n", (type ? type : ""), ref->getRefCount());
         }
     }
 }
@@ -103,7 +103,7 @@ void untrackRef(Ref* ref, void* record)
     RefAllocationRecord* rec = (RefAllocationRecord*)record;
     if (rec->ref != ref)
     {
-        printError("[memory] CORRUPTION: Attempting to free Ref with invalid ref tracking record.");
+        printError("[memory] CORRUPTION: Attempting to free Ref with invalid ref tracking record.\n");
         return;
     }
 

+ 10 - 0
gameplay/src/Theme.cpp

@@ -271,6 +271,7 @@ Theme* Theme::create(const char* url)
                     if (!font)
                     {
                         font = normal->getFont();
+                        font->addRef();
                     }
 
                     unsigned int fontSize;
@@ -349,7 +350,10 @@ Theme* Theme::create(const char* url)
                         focus->setOpacity(opacity);
 
                         if (font)
+                        {
                             theme->_fonts.insert(font);
+                            font->release();
+                        }
                     }
                     else if (strcmp(innerSpacename, "stateActive") == 0)
                     {
@@ -366,7 +370,10 @@ Theme* Theme::create(const char* url)
                         active->setOpacity(opacity);
 
                         if (font)
+                        {
                             theme->_fonts.insert(font);
+                            font->release();
+                        }
                     }
                     else if (strcmp(innerSpacename, "stateDisabled") == 0)
                     {
@@ -383,7 +390,10 @@ Theme* Theme::create(const char* url)
                         disabled->setOpacity(opacity);
 
                         if (font)
+                        {
                             theme->_fonts.insert(font);
+                            font->release();
+                        }
                     }
                 }