From c1e34c5a29d99d8a70b4e78313bfd3d539d9206e Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Tue, 28 May 2024 11:31:03 -0700 Subject: Print memory leak info in Debug build of slangc.exe (#4210) When memory leak is detected, this commit will dump the information about the memory leak. This feature is available only in Debug build on Windows platform. Also note that the message will not be printed on the client applications that use slang.dll, because the printing happens as a part of slangc.exe not slang.dll. I found a bug that Slang::StdWriters was closing `stdout` and `stderr` in its destructor, which prevented Crt functions to print the messages to `stdout` and `stderr`. --- source/slangc/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source/slangc') diff --git a/source/slangc/main.cpp b/source/slangc/main.cpp index 3a01c07e7..b86472617 100644 --- a/source/slangc/main.cpp +++ b/source/slangc/main.cpp @@ -139,6 +139,15 @@ int wmain(int argc, wchar_t** argv) } #ifdef _MSC_VER + // "When _DEBUG isn't defined, calls to _CrtSetReportMode are removed + // during preprocessing." + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + _CrtDumpMemoryLeaks(); #endif -- cgit v1.2.3