From 6f7ecd60732276e4480e60680c224c13a1415b28 Mon Sep 17 00:00:00 2001 From: zhengyang01 Date: Fri, 14 May 2021 14:45:06 +0800 Subject: [PATCH] 1.Fix crash on android by not initialize the tpmalloc in some thread 2.Fix initialization order problem in TRACY_DELAYED_INIT 3.Some warning fix --- client/TracyCallstack.cpp | 1 + client/TracyCallstack.hpp | 5 +++++ client/TracyProfiler.cpp | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index 4c87e6c7..e21d3893 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -163,6 +163,7 @@ void InitCallstack() TRACY_API uintptr_t* CallTrace( int depth ) { + InitRPMallocThread(); auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) ); const auto num = RtlWalkFrameChain( (void**)( trace + 1 ), depth, 0 ); *trace = num; diff --git a/client/TracyCallstack.hpp b/client/TracyCallstack.hpp index f5d4231b..97e69ccd 100644 --- a/client/TracyCallstack.hpp +++ b/client/TracyCallstack.hpp @@ -21,6 +21,7 @@ namespace tracy { +TRACY_API void InitRPMallocThread(); struct CallstackSymbolData { @@ -83,6 +84,8 @@ static _Unwind_Reason_Code tracy_unwind_callback( struct _Unwind_Context* ctx, v static tracy_force_inline void* Callstack( int depth ) { + InitRPMallocThread(); + assert( depth >= 1 && depth < 63 ); auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) ); @@ -98,6 +101,8 @@ static tracy_force_inline void* Callstack( int depth ) static tracy_force_inline void* Callstack( int depth ) { + InitRPMallocThread(); + assert( depth >= 1 ); auto trace = (uintptr_t*)tracy_malloc( ( 1 + (size_t)depth ) * sizeof( uintptr_t ) ); diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 9024c2d7..8bd0bb7a 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -364,7 +364,7 @@ static const char* GetHostInfo() # elif defined __MINGW32__ ptr += sprintf( ptr, "OS: Windows %i.%i.%i (MingW)\n", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber ); # else - ptr += sprintf( ptr, "OS: Windows %i.%i.%i\n", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber ); + ptr += sprintf( ptr, "OS: Windows %i.%i.%i\n", (int)ver.dwMajorVersion, (int)ver.dwMinorVersion, (int)ver.dwBuildNumber ); # endif } #elif defined __linux__ @@ -1007,6 +1007,7 @@ TRACY_API void StartupProfiler() s_profilerData = (ProfilerData*)tracy_malloc( sizeof( ProfilerData ) ); new (s_profilerData) ProfilerData(); s_profilerData->profiler.SpawnWorkerThreads(); + s_instance = &s_profilerData->profiler; } static ProfilerData& GetProfilerData() { @@ -1219,7 +1220,6 @@ Profiler::Profiler() , m_queryData( nullptr ) { assert( !s_instance ); - s_instance = this; #ifndef TRACY_DELAYED_INIT # ifdef _MSC_VER @@ -1250,6 +1250,7 @@ Profiler::Profiler() #if !defined(TRACY_DELAYED_INIT) || !defined(TRACY_MANUAL_LIFETIME) SpawnWorkerThreads(); + s_instance = this; #endif }