From 199dc46e7d80ea104187eaa39b206ad1403e0a62 Mon Sep 17 00:00:00 2001 From: Andrey Voroshilov Date: Wed, 8 Jul 2020 03:50:25 -0700 Subject: [PATCH] Fixing crash on exit due to RP malloc not being deinitialized --- client/TracyProfiler.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 272278d4..334573db 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -929,6 +929,7 @@ TRACY_API void ShutdownProfiler() { delete s_profilerData; s_profilerData = nullptr; + rpmalloc_finalize(); } # else static std::atomic profilerDataLock { 0 }; @@ -1033,6 +1034,7 @@ TRACY_API void ShutdownProfiler() { delete s_profiler; s_profiler = nullptr; + rpmalloc_finalize(); } TRACY_API Profiler& GetProfiler() { return *s_profiler; } # else @@ -1213,12 +1215,25 @@ bool Profiler::ShouldExit() return s_instance->m_shutdown.load( std::memory_order_relaxed ); } +class ThreadExitHandler +{ +public: + ~ThreadExitHandler() + { +#ifdef TRACY_MANUAL_LIFETIME + rpmalloc_thread_finalize(); +#endif + } +}; + void Profiler::Worker() { #ifdef __linux__ s_profilerTid = syscall( SYS_gettid ); #endif + ThreadExitHandler threadExitHandler; + SetThreadName( "Tracy Profiler" ); #ifdef TRACY_DATA_PORT @@ -1639,6 +1654,8 @@ void Profiler::Worker() void Profiler::CompressWorker() { + ThreadExitHandler threadExitHandler; + SetThreadName( "Tracy DXT1" ); while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); rpmalloc_thread_initialize();