From 9b8eb69886bfbc82ba73411f7442c7d27b9711c7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 28 Mar 2020 16:09:44 +0100 Subject: [PATCH] Apparently sampled call stacks may be empty. --- client/TracySysTrace.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index 72e098c4..a9a9597c 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -144,14 +144,17 @@ void WINAPI EventRecordCallback( PEVENT_RECORD record ) if( sw->stackProcess == s_pid && ( sw->stack[0] & 0x8000000000000000 ) == 0 ) { const uint64_t sz = ( record->UserDataLength - 16 ) / 8; - auto trace = (uint64_t*)tracy_malloc( ( 1 + sz ) * sizeof( uint64_t ) ); - memcpy( trace, &sz, sizeof( uint64_t ) ); - memcpy( trace+1, sw->stack, sizeof( uint64_t ) * sz ); - TracyLfqPrepare( QueueType::CallstackSample ); - MemWrite( &item->callstackSample.time, sw->eventTimeStamp ); - MemWrite( &item->callstackSample.thread, (uint64_t)sw->stackThread ); - MemWrite( &item->callstackSample.ptr, (uint64_t)trace ); - TracyLfqCommit; + if( sz > 0 ) + { + auto trace = (uint64_t*)tracy_malloc( ( 1 + sz ) * sizeof( uint64_t ) ); + memcpy( trace, &sz, sizeof( uint64_t ) ); + memcpy( trace+1, sw->stack, sizeof( uint64_t ) * sz ); + TracyLfqPrepare( QueueType::CallstackSample ); + MemWrite( &item->callstackSample.time, sw->eventTimeStamp ); + MemWrite( &item->callstackSample.thread, (uint64_t)sw->stackThread ); + MemWrite( &item->callstackSample.ptr, (uint64_t)trace ); + TracyLfqCommit; + } } } break;