D3DXCompileShader 在 Visual Studio 之外运行时出现奇怪的错误

发布于 2024-11-07 06:37:29 字数 1333 浏览 3 评论 0原文

我真的有两个问题。

第一个更多的是对事件的描述:软件使用 DirectX 9 并在启动时从资源编译着色器。当您从 IDE 中运行该软件时,着色器可以在调试版本和发布版本中编译良好,但是当您双击它以独立运行它时,您开始从 D3DXCompileShader 中收到许多奇怪的错误。

我将此归因于 Visual Studio 已将着色器文本文件转换为 Unicode 的可能性,并且这会以某种方式引发 D3DXCompileShader。为什么当我在 IDE 内而不是在 IDE 之外时它们可以编译并运行正常,这是一个谜(注意,如果您在 VS 外部启动它,然后将调试器附加到进程,它仍然会失败)。有人对此有什么想法吗?

我的第二个问题涉及解决上述问题的尝试。我没有使用自己的名为 SHADER 的资源数据类型,而是将着色器导入为 RCDATA,因此我现在可以使用 D3DXCompileShaderFromResource,而不是自己从资源中手动加载着色器文本。然而,我从对此的调用中得到了错误的 HRESULT,但“错误”集合仍然为空。它根本没有调试输出。代码如下所示:

HRESULT result;

result = D3DXCompileShaderFromResource( 0, 
                                        MAKEINTRESOURCE(IDR_SHADERPHONG),
                                        NULL, 
                                        NULL, 
                                        "VERTEXMAIN",
                                        D3DXGetVertexShaderProfile(Window()->GetDevice()),
                                        D3DXSHADER_OPTIMIZATION_LEVEL3,
                                        &MyVertexShaderBuffer,
                                        &errors,
                                        &MyVertexShaderConstants);

HRESULT 为-2005529767,这似乎是“失败”。我在互联网上找不到任何关于它与 D3DXCompileShaderFromResource 相关的含义的参考!

我希望我在 stackoverflow 的聪明朋友可以在这里提供一些帮助:p。谢谢。


I've got two questions really.

The first is more a description of events: software uses DirectX 9 and compiles shaders at start-up from resources. The shaders compile fine with both debug and release versions when you run the software from within the IDE, but when you double-click it to run it stand-alone, you start getting lots of weird errors from D3DXCompileShader.

I have put this down to the possibility that Visual Studio has converted the shader text files to Unicode and that this is throwing D3DXCompileShader somehow. Why they compile and run ok when I'm within the IDE but not outside of it is a mystery (note, it still fails if you launch it outside of VS and then attach the debugger to the process). Anyone have any thoughts on this?

My second question relates to attempts to fix the above. Instead of having my own resource data type called SHADER, I've imported a shader as RCDATA, so instead of manually loading the shader text from the resource myself, I'm now able to use D3DXCompileShaderFromResource. I'm getting a bad HRESULT from my call to this however, but the `errors' collection remains empty. There is no debug output from it at all. The code looks like this:

HRESULT result;

result = D3DXCompileShaderFromResource( 0, 
                                        MAKEINTRESOURCE(IDR_SHADERPHONG),
                                        NULL, 
                                        NULL, 
                                        "VERTEXMAIN",
                                        D3DXGetVertexShaderProfile(Window()->GetDevice()),
                                        D3DXSHADER_OPTIMIZATION_LEVEL3,
                                        &MyVertexShaderBuffer,
                                        &errors,
                                        &MyVertexShaderConstants);

The HRESULT is -2005529767, which seems to be "failed". I can find no references on the interwebs to what it can mean in relation to D3DXCompileShaderFromResource!

I'm hoping my clever friends at stackoverflow can offer some assistance here :p. Thanks.


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紧拥背影 2024-11-14 06:37:29

好的,问题找到了(被同事发现)。加载资源时,我抓取了一个内存块并将其错误地转换为 std::string。也就是说, std::string 将遍历资源寻找空终止符,但资源数据不一定有空终止符(它只是一个文本文件)。然而,它最终会找到一个,可能是在软件不应该使用的内存的某些部分!

因此,要将 char 缓冲区从资源转换为 std::string,应使用以下内容:

return std::string(reinterpret_cast<char const*>(pD), bytes);

而不是 this:

return std::string(pD);

,除非您确定 pD 指向以 null 结尾的字符串。

OK, the problem was found (by a colleague). When loading my resource I was grabbing a memory block and incorrectly converting it to std::string. That is, std::string will go through the resource looking for a null terminator, but the resource data won't necessarily have one (it's just a text file). It will eventually find one, however, probably in some part of memory the software isn't supposed to be using!

So, to convert a char buffer from a resource into a std::string, the following should be used:

return std::string(reinterpret_cast<char const*>(pD), bytes);

not this:

return std::string(pD);

, unless of course you know for sure that pD points to a null-terminated string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文