瀏覽代碼

initial commit

This change makes the memory manager work again for detecting leaks, the built in one kept coming into de-ref and other bugs so this is the start of a refactor to get it working.
marauder2k7 5 月之前
父節點
當前提交
8c812cb448

+ 0 - 34
Engine/source/app/mainLoop.cpp

@@ -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
 // Process a time event and update all sub-processes
 void processTimeEvent(S32 elapsedTime)
 void processTimeEvent(S32 elapsedTime)
 {
 {
@@ -216,10 +193,6 @@ void StandardMainLoop::init()
    gStartupTimer = PlatformTimer::create();
    gStartupTimer = PlatformTimer::create();
    #endif
    #endif
    
    
-   #ifdef TORQUE_DEBUG_GUARD
-      Memory::flagCurrentAllocs( Memory::FLAG_Global );
-   #endif
-
    Platform::setMathControlStateKnown();
    Platform::setMathControlStateKnown();
    
    
    // Asserts should be created FIRST
    // Asserts should be created FIRST
@@ -327,10 +300,6 @@ void StandardMainLoop::init()
 
 
    // Hook in for UDP notification
    // Hook in for UDP notification
    Net::getPacketReceiveEvent().notify(GNet, &NetInterface::processPacketReceiveEvent);
    Net::getPacketReceiveEvent().notify(GNet, &NetInterface::processPacketReceiveEvent);
-
-   #ifdef TORQUE_DEBUG_GUARD
-      Memory::flagCurrentAllocs( Memory::FLAG_Static );
-   #endif
 }
 }
 
 
 void StandardMainLoop::shutdown()
 void StandardMainLoop::shutdown()
@@ -378,9 +347,6 @@ void StandardMainLoop::shutdown()
    // asserts should be destroyed LAST
    // asserts should be destroyed LAST
    PlatformAssert::destroy();
    PlatformAssert::destroy();
 
 
-#if defined( TORQUE_DEBUG ) && !defined( TORQUE_DISABLE_MEMORY_MANAGER )
-   Memory::validate();
-#endif
 }
 }
 
 
 void StandardMainLoop::preShutdown()
 void StandardMainLoop::preShutdown()

+ 9 - 2
Engine/source/main/main.cpp

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

文件差異過大導致無法顯示
+ 146 - 1588
Engine/source/platform/platformMemory.cpp


+ 12 - 23
Engine/source/platform/platformMemory.h

@@ -27,33 +27,22 @@
 
 
 namespace Memory
 namespace Memory
 {
 {
-   enum EFlag
+   struct MemInfo
    {
    {
-      FLAG_Debug,
-      FLAG_Global,
-      FLAG_Static
-   };
+      void* ptr;
+      dsize_t size;
+      const char* file;
+      U32 line;
+      U32 allocId;
+      bool flagged;
 
 
-   struct Info
-   {
-      U32         mAllocNumber;
-      U32         mAllocSize;
-      const char* mFileName;
-      U32         mLineNumber;
-      bool        mIsArray;
-      bool        mIsGlobal;
-      bool        mIsStatic;
+      void* backtracePtrs[16];
+      int backtraceSize;
    };
    };
 
 
-   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 checkPtr(void* ptr);
 }
 }
 
 
 #endif // _TORQUE_PLATFORM_PLATFORMMEMORY_H_
 #endif // _TORQUE_PLATFORM_PLATFORMMEMORY_H_

+ 11 - 0
Engine/source/ts/assimp/assimpAppMaterial.cpp

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

+ 12 - 0
Engine/source/ts/assimp/assimpAppMaterial.h

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

+ 12 - 0
Engine/source/ts/assimp/assimpAppMesh.cpp

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

+ 13 - 0
Engine/source/ts/assimp/assimpAppNode.cpp

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

+ 12 - 0
Engine/source/ts/assimp/assimpAppNode.h

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

+ 12 - 0
Engine/source/ts/assimp/assimpAppSequence.h

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

+ 11 - 0
Engine/source/ts/assimp/assimpShapeLoader.cpp

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

部分文件因文件數量過多而無法顯示