From 5e9844a4e5d0f4ca521a1f5d42deb71f65dafcc5 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 5 Jan 2026 10:03:14 +0800 Subject: [PATCH] [Chore] (MG_Util/Debug/Log): give up on stacktrace --- MobileGL/Defines.h | 3 ++- MobileGL/Includes.h | 3 +++ MobileGL/MG_Util/Debug/Log.cpp | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/MobileGL/Defines.h b/MobileGL/Defines.h index 564bdc5c..c1bd01fc 100644 --- a/MobileGL/Defines.h +++ b/MobileGL/Defines.h @@ -45,7 +45,8 @@ #define MOBILEGL_LOG_ENABLE_ANDROID 1 // Require C++23 -#if __cplusplus >= 202302L +// Android NDK still doesn't have support for that :( +#if __cplusplus >= 202302L && !__ANDROID__ #define MOBILEGL_LOG_ENABLE_STACKTRACE 1 #endif diff --git a/MobileGL/Includes.h b/MobileGL/Includes.h index 73a2c566..55bb3dc8 100644 --- a/MobileGL/Includes.h +++ b/MobileGL/Includes.h @@ -41,6 +41,9 @@ #include #include #include +#if __cplusplus >= 202302L && MOBILEGL_LOG_ENABLE_STACKTRACE +#include +#endif // Include FastSTL #include diff --git a/MobileGL/MG_Util/Debug/Log.cpp b/MobileGL/MG_Util/Debug/Log.cpp index 434d89b4..75f007c6 100644 --- a/MobileGL/MG_Util/Debug/Log.cpp +++ b/MobileGL/MG_Util/Debug/Log.cpp @@ -76,6 +76,11 @@ namespace MobileGL { void Log(const char* levelTag, android_LogPriority androidLogLevel, const char* fmt, ...) { std::lock_guard lock(s_mutex); +#if MOBILEGL_LOG_ENABLE_STACKTRACE + auto trace = std::stacktrace::current(); + std::string padding(4 * trace.size(), ' '); +#endif + std::string header = "[" + GetCurrentTime() + "] [" + GetOSName() + " " + GetThreadName() + "/" + levelTag + "]: "; @@ -83,7 +88,11 @@ namespace MobileGL { va_list args; va_start(args, fmt); int n = std::vsnprintf(buffer, sizeof(buffer), fmt, args); - std::string out = header + std::string(buffer, n) + "\n"; + std::string out = header + +#if MOBILEGL_LOG_ENABLE_STACKTRACE + padding + +#endif + std::string(buffer, n) + "\n"; #if MOBILEGL_LOG_ENABLE_CONSOLE std::fwrite(out.c_str(), 1, out.size(), stdout);