wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
8.64k stars 595 forks source link

Profiler crashes when it fails to allocate memory #728

Closed idbrii closed 2 months ago

idbrii commented 4 months ago

I left a sample running (looking for memory leaks) and it looks like it ran for 5 hours and then crashed:

image

Tracy's using a lot of memory and seems like it ran out. Would be nice if I could set a memory use limit (or time limit?) and it would automatically stop recording at that point. Do I need to use capture.exe for that kind of use case?


This isn't the first time so I left a debugger attached to the profiler. Using Tracy Release build. Callstack:

    vcruntime140.dll!memcpy() Line 433  Unknown
>   Tracy.exe!tracy::Vector<tracy::ChildSample>::AllocMore() Line 302   C++
    Tracy.exe!tracy::Worker::Exec() Line 2828   C++
    [External Code] 

That's here:

        else
        {
            memUsage += Capacity() * sizeof( T );
            m_capacity++;
            Realloc();      // Tracy.exe: 0xC0000005: Access violation writing location 0x0000000000000020
        }

Looking into Realloc, it doesn't check the pointer it receives is not null:

    void Realloc()
    {
        T* ptr = (T*)malloc( sizeof( T ) * CapacityNoNullptrCheck() );
        if( m_size != 0 )
        {
            if( std::is_trivially_copyable<T>() )
            {
                memcpy( (char*)ptr, m_ptr, m_size * sizeof( T ) );

I'm using tracy v0.10 37aff70dfa50cf6307b3fee6074d627dc2929143 plus cherry picked 5ce238e.

wolfpld commented 2 months ago

It is now possible to set a memory limit.