From 42f5d4feba1add5288917285b1e642d936ba45c0 Mon Sep 17 00:00:00 2001 From: RH Date: Sun, 15 Dec 2024 02:18:08 +1100 Subject: [PATCH] Add printLeaks call in appropriate location to help developers (#2275) Add the printLeaks call in the correct location to help developers locate leaks in their apps if leak detection is enabled --- templates/common/proj.ios_mac/mac/main.cpp | 14 +++++++++++++- templates/common/proj.linux/main.cpp | 13 ++++++++++++- templates/common/proj.wasm/main.cpp | 13 ++++++++++++- templates/common/proj.win32/main.cpp | 10 +++++++--- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/templates/common/proj.ios_mac/mac/main.cpp b/templates/common/proj.ios_mac/mac/main.cpp index 56ebe43cb56..6060c9e0177 100644 --- a/templates/common/proj.ios_mac/mac/main.cpp +++ b/templates/common/proj.ios_mac/mac/main.cpp @@ -29,8 +29,20 @@ using namespace ax; -int main(int argc, char* argv[]) +int axmol_main() { + // create the application instance AppDelegate app; return Application::getInstance()->run(); } + +int main(int argc, char* argv[]) +{ + auto result = axmol_main(); + +#if AX_OBJECT_LEAK_DETECTION + Object::printLeaks(); +#endif + + return result; +} diff --git a/templates/common/proj.linux/main.cpp b/templates/common/proj.linux/main.cpp index 06161d1fb1a..fee53bf5959 100644 --- a/templates/common/proj.linux/main.cpp +++ b/templates/common/proj.linux/main.cpp @@ -32,9 +32,20 @@ using namespace ax; -int main(int argc, char** argv) +int axmol_main() { // create the application instance AppDelegate app; return Application::getInstance()->run(); } + +int main(int argc, char** argv) +{ + auto result = axmol_main(); + +#if AX_OBJECT_LEAK_DETECTION + Object::printLeaks(); +#endif + + return result; +} diff --git a/templates/common/proj.wasm/main.cpp b/templates/common/proj.wasm/main.cpp index 8d5c2faa6bc..5256b0e10d1 100644 --- a/templates/common/proj.wasm/main.cpp +++ b/templates/common/proj.wasm/main.cpp @@ -33,9 +33,20 @@ using namespace ax; -int main(int argc, char** argv) +int axmol_main() { // create the application instance AppDelegate app; return Application::getInstance()->run(); } + +int main(int argc, char** argv) +{ + auto result = axmol_main(); + +#if AX_OBJECT_LEAK_DETECTION + Object::printLeaks(); +#endif + + return result; +} diff --git a/templates/common/proj.win32/main.cpp b/templates/common/proj.win32/main.cpp index 00f0919f37e..97a42993104 100644 --- a/templates/common/proj.win32/main.cpp +++ b/templates/common/proj.win32/main.cpp @@ -45,13 +45,17 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - // create the application instance #ifdef USE_WIN32_CONSOLE # include "platform/win32/EmbedConsole.h" #endif - // create the application instance - return axmol_main(); + auto result = axmol_main(); + +#if AX_OBJECT_LEAK_DETECTION + Object::printLeaks(); +#endif + + return result; } #else int main(int, char**) {