summaryrefslogtreecommitdiffstats
path: root/src/Globals.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2017-06-19 11:09:16 +0200
committerGitHub <noreply@github.com>2017-06-19 11:09:16 +0200
commitb0f3336533e104e3d0cf087858b616e3411f117a (patch)
treea08bc4f6d7a872b71f8ed5cbbb707b941b7ddb85 /src/Globals.h
parentLuaState: Fixed VS2017's throw warnings for destructors. (#3779) (diff)
downloadcuberite-b0f3336533e104e3d0cf087858b616e3411f117a.tar
cuberite-b0f3336533e104e3d0cf087858b616e3411f117a.tar.gz
cuberite-b0f3336533e104e3d0cf087858b616e3411f117a.tar.bz2
cuberite-b0f3336533e104e3d0cf087858b616e3411f117a.tar.lz
cuberite-b0f3336533e104e3d0cf087858b616e3411f117a.tar.xz
cuberite-b0f3336533e104e3d0cf087858b616e3411f117a.tar.zst
cuberite-b0f3336533e104e3d0cf087858b616e3411f117a.zip
Diffstat (limited to 'src/Globals.h')
-rw-r--r--src/Globals.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Globals.h b/src/Globals.h
index 4e15473e1..f7116f8e0 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -60,6 +60,24 @@
// Use non-standard defines in <cmath>
#define _USE_MATH_DEFINES
+ #ifdef _DEBUG
+ // Override the "new" operator to include file and line specification for debugging memory leaks
+ // Ref.: https://social.msdn.microsoft.com/Forums/en-US/ebc7dd7a-f3c6-49f1-8a60-e381052f21b6/debugging-memory-leaks?forum=vcgeneral#53f0cc89-62fe-45e8-bbf0-56b89f2a1901
+ // This causes MSVC Debug runs to produce a report upon program exit, that contains memory-leaks
+ // together with the file:line information about where the memory was allocated.
+ // Note that this doesn't work with placement-new, which needs to temporarily #undef the macro
+ // (See AllocationPool.h for an example).
+ #ifdef _DEBUG
+ #define _CRTDBG_MAP_ALLOC
+ #include <stdlib.h>
+ #include <crtdbg.h>
+ #define DEBUG_CLIENTBLOCK new(_CLIENT_BLOCK, __FILE__, __LINE__)
+ #define new DEBUG_CLIENTBLOCK
+ // For some reason this works magically - each "new X" gets replaced as "new(_CLIENT_BLOCK, "file", line) X"
+ // The CRT has a definition for this operator new that stores the debugging info for leak-finding later.
+ #endif
+ #endif
+
#elif defined(__GNUC__)
// TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?