mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
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.
This commit is contained in:
parent
13bf126418
commit
8c812cb448
11 changed files with 258 additions and 1665 deletions
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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");
|
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
|
||||||
// Memory::setBreakAlloc(104717);
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -27,33 +27,22 @@
|
||||||
|
|
||||||
namespace Memory
|
namespace Memory
|
||||||
{
|
{
|
||||||
enum EFlag
|
struct MemInfo
|
||||||
{
|
{
|
||||||
FLAG_Debug,
|
void* ptr;
|
||||||
FLAG_Global,
|
dsize_t size;
|
||||||
FLAG_Static
|
const char* file;
|
||||||
|
U32 line;
|
||||||
|
U32 allocId;
|
||||||
|
bool flagged;
|
||||||
|
|
||||||
|
void* backtracePtrs[16];
|
||||||
|
int backtraceSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Info
|
void init();
|
||||||
{
|
void shutdown();
|
||||||
U32 mAllocNumber;
|
void checkPtr(void* ptr);
|
||||||
U32 mAllocSize;
|
|
||||||
const char* mFileName;
|
|
||||||
U32 mLineNumber;
|
|
||||||
bool mIsArray;
|
|
||||||
bool mIsGlobal;
|
|
||||||
bool mIsStatic;
|
|
||||||
};
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _TORQUE_PLATFORM_PLATFORMMEMORY_H_
|
#endif // _TORQUE_PLATFORM_PLATFORMMEMORY_H_
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue