baldurk / renderdoc

RenderDoc is a stand-alone graphics debugging tool.
https://renderdoc.org
MIT License
9.11k stars 1.36k forks source link

Access violation in StreamWriter::Write during a DX12 capture #1998

Closed barycz closed 4 years ago

barycz commented 4 years ago

Description

This crash occurs when trying to capture CryEngine GameLauncher.exe, but is maybe reproducible with other apps too.

    vcruntime140.dll!00007ff9d62415b9() Unknown
>   renderdoc.dll!StreamWriter::Write(const void * data, unsigned __int64 numBytes) Line 360    C++
    renderdoc.dll!Serialiser<0>::Serialise(const rdcliteral & name, unsigned char * & el, unsigned __int64 byteSize, SerialiserFlags flags) Line 286    C++
    renderdoc.dll!WrappedID3D12Device::Serialise_MapDataWrite<WriteSerialiser>(WriteSerialiser & ser, ID3D12Resource * Resource, unsigned int Subresource, unsigned char * MappedData, D3D12_RANGE range) Line 1311 C++
    renderdoc.dll!WrappedID3D12Device::MapDataWrite(ID3D12Resource * Resource, unsigned int Subresource, unsigned char * mapPtr, D3D12_RANGE range) Line 1404   C++
    renderdoc.dll!WrappedID3D12CommandQueue::ExecuteCommandListsInternal(unsigned int NumCommandLists, ID3D12CommandList * const * ppCommandLists, bool InFrameCaptureBoundary, bool SkipRealExecute) Line 519  C++
    renderdoc.dll!WrappedID3D12CommandQueue::ExecuteCommandLists(unsigned int NumCommandLists, ID3D12CommandList * const * ppCommandLists) Line 333 C++
    CryRenderD3D12.dll!00007ff968565f61()   Unknown
    CrySystem.dll!00007ff96cfe26ab()    Unknown
    ucrtbase.dll!00007ff9f1971542() Unknown
    kernel32.dll!00007ff9f24c6fd4() Unknown
    ntdll.dll!00007ff9f417cec1()    Unknown

Steps to reproduce

Please note, that this crash sometimes does not occur when running the application with an attached debugger. So I guess it is somehow related to the timing of the execution and may not be easily reproducible.

Environment

Thank you!

baldurk commented 4 years ago

This was caused by a mapped resource being serialised during submission of a command buffer that used it, while on another thread that resource was being unmapped. The race lead to RenderDoc ending up with a NULL map pointer.

That commit should fix it.