Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracy-instrumented application crashes in Tracy's static intializers when started through RenderDoc #71

Closed
simonvanbernem opened this issue Jul 9, 2020 · 5 comments

Comments

@simonvanbernem
Copy link
Contributor

When I try to start my game, which is instrumented using tracy, in RenderDoc, the game instantly crashes due to a static variable of Tracy's moodycamel queue failing to initialize. The actual violation is a nullptr dereference inside a critical section of malloc.

This is a bug that seems to be the result of some weird interaction and the tool RenderDoc: I originally thought this was an issue with RenderDoc, and reported it, but the maintainer pointed out to me that this is actually a crash in my application (see the issue at RenderDoc's Github for details).

The stacktrace shows that the crash happens, when malloc tries to take a lock duing the initialization of a ProducerToken inside of Tracy:

RtlpWaitOnCriticalSection
RtlpEnterCriticalSectionContended
RtlEnterCriticalSection
__acrt_lock Line 55 at minkernel\crts\ucrt\src\appcrt\internal\locks.cpp(55)
heap_alloc_dbg_internal Line 309 at minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp(309)
heap_alloc_dbg Line 450 at minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp(450)
_malloc_dbg Line 496 at minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp(496)
tracy::moodycamel::ConcurrentQueueDefaultTraits::WORKAROUND_malloc Line 224 at B:\spaced\source\tracy\client\tracy_concurrentqueue.h(224)
tracy::moodycamel::ConcurrentQueueDefaultTraits::malloc Line 226 at B:\spaced\source\tracy\client\tracy_concurrentqueue.h(226)
tracy::moodycamel::ConcurrentQueuetracy::QueueItem,tracy::moodycamel::ConcurrentQueueDefaultTraits::create<tracy::moodycamel::ConcurrentQueuetracy::QueueItem,tracy::moodycamel::ConcurrentQueueDefaultTraits::ExplicitProducer,tracy::moodycamel::ConcurrentQueuetracy::QueueItem,tracy::moodycamel::ConcurrentQueueDefaultTraits *> Line 1428 at B:\spaced\source\tracy\client\tracy_concurrentqueue.h(1428)
tracy::moodycamel::ConcurrentQueuetracy::QueueItem,tracy::moodycamel::ConcurrentQueueDefaultTraits::recycle_or_create_producer Line 1366 at B:\spaced\source\tracy\client\tracy_concurrentqueue.h(1366)
tracy::moodycamel::ConcurrentQueuetracy::QueueItem,tracy::moodycamel::ConcurrentQueueDefaultTraits::recycle_or_create_producer Line 1346 at B:\spaced\source\tracy\client\tracy_concurrentqueue.h(1346)
tracy::moodycamel::ProducerToken::ProducerTokentracy::QueueItem,tracy::moodycamel::ConcurrentQueueDefaultTraits Line 1458 at B:\spaced\source\tracy\client\tracy_concurrentqueue.h(1458)
tracy::`dynamic initializer for 's_token_detail'' Line 975 at B:\spaced\source\tracy\client\TracyProfiler.cpp(975)
__dyn_tls_init Line 79 at d:\agent_work\5\s\src\vctools\crt\vcstartup\src\tls\tlsdyn.cpp(79)
LdrpCallInitRoutine
LdrpCallTlsInitializers
LdrpInitializeThread
_LdrpInitialize
LdrpInitialize
LdrInitializeThunk

The maintainer of RenderDocs guess on the bug is the following:

If I had to guess I'd say that your code enters a critical section in some static initialiser that runs on thread attach, but the critical section isn't initialised until after main() is entered. RenderDoc injects a thread to insert its hooks which will run before main(), so any global initialisers that are fragile like this can break.

Now. I don't really know if this a bug in your code, or moodycamels, or even MSVC C++ library, but since you have comments in TracyProfiler.cpp that mention binary sections and initialization just above the code in question (lines 974 and 975) I hope that you might know how to fix this.

I am on tracy version 0.7

If you need to repro the issue, I can send you my application+renderdoc and instructions on how to repro. It should take only a couple of minutes.

@wolfpld
Copy link
Owner

wolfpld commented Jul 9, 2020

Sorry, I can't reproduce this. On my side RenderDoc is able to correctly launch a profiled application.

Have you tried compiling your program with TRACY_DELAYED_INIT define?

@simonvanbernem
Copy link
Contributor Author

TRACY_DELAYED_INIT did the trick, thanks! I can send you my application for repro if you want to dig into this, although I understand if you don't want to.

@wolfpld
Copy link
Owner

wolfpld commented Jul 9, 2020

Sure, I can take a look.

@simonvanbernem
Copy link
Contributor Author

I sent you a mail with a link to my OneDrive.

@wolfpld
Copy link
Owner

wolfpld commented Aug 6, 2020

Closing, as a workaround exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants