From e014129b12b8ab5af5f460ac7fed9c7e79481525 Mon Sep 17 00:00:00 2001 From: OV2 Date: Fri, 13 Oct 2017 22:37:39 +0200 Subject: [PATCH] win32: rework CHECK_MEMORY_LEAKS to dump after static object deinit --- win32/DumpAtEnd.cpp | 17 +++++++++++++++++ win32/snes9xw.vcxproj | 1 + win32/snes9xw.vcxproj.filters | 3 +++ win32/wsnes9x.cpp | 7 ------- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 win32/DumpAtEnd.cpp diff --git a/win32/DumpAtEnd.cpp b/win32/DumpAtEnd.cpp new file mode 100644 index 00000000..9a8ba699 --- /dev/null +++ b/win32/DumpAtEnd.cpp @@ -0,0 +1,17 @@ +// uncomment to find memory leaks at end +// #define CHECK_MEMORY_LEAKS + +// to also display file locations in some cases define _CRTDBG_MAP_ALLOC in the project properties + +#ifdef CHECK_MEMORY_LEAKS +// hack to make sure this object is destructed last +// msvc merges .CRT$XC in alphabetic order +// might not work in other versions of MSVC +#pragma init_seg(".CRT$XCB") +struct CallDumpMemLeaksLast { + ~CallDumpMemLeaksLast() { + _CrtDumpMemoryLeaks(); + } +}; +static CallDumpMemLeaksLast dump_last; +#endif \ No newline at end of file diff --git a/win32/snes9xw.vcxproj b/win32/snes9xw.vcxproj index fe395fca..731c2f43 100644 --- a/win32/snes9xw.vcxproj +++ b/win32/snes9xw.vcxproj @@ -534,6 +534,7 @@ + diff --git a/win32/snes9xw.vcxproj.filters b/win32/snes9xw.vcxproj.filters index 454ddcd8..f2a1e4f9 100644 --- a/win32/snes9xw.vcxproj.filters +++ b/win32/snes9xw.vcxproj.filters @@ -539,6 +539,9 @@ APU + + GUI + diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index c67b5fc7..ebc4790a 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -244,13 +244,6 @@ #include "wlanguage.h" #include "../language.h" -//uncomment to find memory leaks, with a line in WinMain -//#define CHECK_MEMORY_LEAKS - -#ifdef CHECK_MEMORY_LEAKS - #include -#endif - #include #include #include