简体   繁体   English

Visual Studio 图形调试器引发读取访问冲突异常

[英]Visual Studio Graphics Debugger throws read access violation exception

I'm writing a simple renderer using the d3d11 library in Visual Studio 2019 and it builds and runs fine.我正在使用 Visual Studio 2019 中的 d3d11 库编写一个简单的渲染器,它可以正常构建和运行。 However when I try running the Graphics Debugger it immediately throws a read access violation for address 0x0000000000000000 ( which is clearly incorrect ).但是,当我尝试运行图形调试器时,它会立即引发地址 0x0000000000000000 的读取访问冲突(这显然是不正确的)。

The exception is thrown from the DXCaptureReplay dll on the line从线上的DXCaptureReplay dll抛出异常

DeviceContext.PSSetShader(InShaderToBind.Shader.PS, NULL, 1);

Where InShaderToBind.Shader.PS is a pointer to ID3D11PixelShader其中 InShaderToBind.Shader.PS 是指向 ID3D11PixelShader 的指针

It got the most weird when I out of a lack of ideas tried当我出于缺乏想法尝试时,它变得最奇怪

int X = 0;
ID3D11ClassInstance* FakedClassInstance = reinterpret_cast<ID3D11ClassInstance*>(&X);

DeviceContext.PSSetShader(InShaderToBind.Shader.PS, &FakedClassInstance, 1);

As this will make the exception not throw until I try to capture a frame ( Which I guess makes sense as that pointer will only be valid for the scope where X is still valid )因为这将使异常在我尝试捕获帧之前不会抛出(我想这是有道理的,因为该指针仅对 X 仍然有效的 scope 有效)

The MSDN documentation states that NULL should be a perfectly valid argument to pass to PSSetShader ( as noted here: https://docs.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-pssetshader ) MSDN 文档指出 NULL 应该是传递给 PSSetShader 的完全有效的参数(如此处所述: https://docs.microsoft.com/en-us/windows/win32/api/d3d11/11111d3dsetshader-id3 )

Any ideas for what might be going wrong?关于可能出现问题的任何想法?

( If I comment out PSSetShader the exception is not thrown and I can take captures ) (如果我注释掉 PSSetShader,则不会引发异常,我可以进行捕获)

If you enable the Direct3D Debug Device, you would see in your debug output window:如果启用 Direct3D 调试设备,您将在调试 output window 中看到:

D3D11 CORRUPTION: ID3D11DeviceContext::PSSetShader: Second parameter (ppClassInstances) corrupt or unexpectedly NULL. [ MISCELLANEOUS CORRUPTION #14: CORRUPTED_PARAMETER2]

NULL (or better yet nullptr ) is fine for ppClassInstances only if NumClassInstances is 0. Try:当 NumClassInstances 为 0 时, NULL (或更好的nullptr )才适用于ppClassInstances 。尝试:

DeviceContext.PSSetShader(InShaderToBind.Shader.PS, NULL, 0);

Generally you should make sure your program runs without emitting ERROR or CORRUPTION messages from the debug layer before attempting to use PIX or the VSGS tool.通常,在尝试使用 PIX 或 VSGS 工具之前,您应该确保您的程序运行时不会从调试层发出 ERROR 或 CORRUPTION 消息。

See Microsoft Docs and this blog post .请参阅Microsoft Docs此博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么调试器会抛出“读取访问冲突”。 这是nullptr”异常吗? - Why is the debugger throwing “read access violation. this was nullptr” exception? 引发Visual Studio C ++异常:读取访问冲突。 使用命令行参数进行调试时 - Visual Studio C++ Exception thrown: read access violation. When debugging using Command Line Argument 写入 function 在 Visual Studio c++ 中引发读取访问冲突异常 - a write function throwing the exception of read access violation in visual studio c++ CreateDibSection引发访问冲突异常 - CreateDibSection throws Access Violation Exception cv :: SimpleBlobDetector detect()在Visual Studio 2010中产生访问冲突异常 - cv::SimpleBlobDetector detect() produce access violation exception in Visual Studio 2010 在Visual Studio中删除二进制搜索树中的节点中的访问冲突异常 - Access Violation Exception in Visual Studio in Deletion of node in Binary Search Tree C ++在Visual Studio中的双向链表中读取访问冲突 - C++ Read access violation in doubly linked list in Visual Studio Visual Studio 2010上的访问冲突 - Access Violation on Visual Studio 2010 抛出异常:读取访问冲突**this** - Exception thrown: read access violation **this** dbgheap.c引发访问冲突异常 - dbgheap.c throws access violation exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM