From 2e3e8dd910e2f9dc81097b8b32b45747d5322a4d Mon Sep 17 00:00:00 2001 From: Nic0Nic0Nii <89110903+Nic0Nic0Nii@users.noreply.github.com> Date: Mon, 29 Jan 2024 19:01:51 +0000 Subject: [PATCH] Add debug flag when building emscripten in debug mode. Co-authored-by: sigonasr2 --- .../AdventuresInLestoria.cpp | 50 ++++++++++--------- Adventures in Lestoria/Error.h | 14 ++++-- .../assets/config/configuration.txt | 2 +- CMakeLists.txt | 6 +++ debug.sh | 2 +- emscripten_debug_build.ps1 | 2 +- 6 files changed, 47 insertions(+), 29 deletions(-) diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 494238bb..855d0346 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -2233,31 +2233,35 @@ int main() } #ifdef _DEBUG - HANDLE hLogFile; - hLogFile = CreateFile(L"assets/memoryleak.txt", GENERIC_WRITE, - FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, - FILE_ATTRIBUTE_NORMAL, NULL); - _CrtSetReportMode(_CRT_WARN,_CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_WARN,hLogFile); - _CrtDumpMemoryLeaks(); - CloseHandle(hLogFile); - - std::ifstream file("assets/memoryleak.txt"); - bool leaked=false; - while(file.good()){ - std::string line; - std::getline(file,line); - if(line.find("AiL\\")!=std::string::npos){ - if(!leaked){ - leaked=true; - std::cout< #ifdef _DEBUG - #define NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) - // Replace _NORMAL_BLOCK with _CLIENT_BLOCK if you want the - // allocations to be of _CLIENT_BLOCK type +#ifndef __EMSCRIPTEN__ +#ifndef __linux__ + #define NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ ) + // Replace _NORMAL_BLOCK with _CLIENT_BLOCK if you want the + // allocations to be of _CLIENT_BLOCK type +#else + #define NEW new +#endif +#else + #define NEW new +#endif #else #define NEW new #endif diff --git a/Adventures in Lestoria/assets/config/configuration.txt b/Adventures in Lestoria/assets/config/configuration.txt index 6b10f41e..05802dd1 100644 --- a/Adventures in Lestoria/assets/config/configuration.txt +++ b/Adventures in Lestoria/assets/config/configuration.txt @@ -120,7 +120,7 @@ debug_access_options = 0 debug_menu_navigation_info = 0 # Shows map loading output -debug_map_load_info = 1 +debug_map_load_info = 0 # Shows state transition information debug_transition_info = 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d83ac7c..86e1cc08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -311,6 +311,12 @@ if (EMSCRIPTEN) # Build Cache: SDL2_mixer, libpng, zlib execute_process(COMMAND "${EMSCRIPTEN_ROOT_PATH}/embuilder${EMCC_SUFFIX}" build sdl2_mixer freetype libpng zlib) + + target_compile_definitions( + ${OutputExecutable} + PUBLIC + $<$:_DEBUG> + ) if(EXISTS "${SOURCE_DATA_DIR}" AND IS_DIRECTORY "${SOURCE_DATA_DIR}") target_link_options( diff --git a/debug.sh b/debug.sh index 8f1856e5..ee4fcf21 100755 --- a/debug.sh +++ b/debug.sh @@ -1 +1 @@ -cmake -DCMAKE_BUILD_TYPE=Debug .;make -j 8 +cmake -DCMAKE_BUILD_TYPE=Debug -D_DEBUG=1 .;make -j 8 diff --git a/emscripten_debug_build.ps1 b/emscripten_debug_build.ps1 index dd23ac42..1892785d 100644 --- a/emscripten_debug_build.ps1 +++ b/emscripten_debug_build.ps1 @@ -1,3 +1,3 @@ clear -emcmake cmake -DCMAKE_BUILD_TYPE=Debug . +emcmake cmake -DCMAKE_BUILD_TYPE=Debug -D_DEBUG=1 . cmake --build . -j 8 \ No newline at end of file