【问题标题】:Error creating effect from memory (c++, directx 11)从内存创建效果时出错(c++,directx 11)
【发布时间】:2016-04-06 01:36:47
【问题描述】:

我正在尝试从我编译的着色器中创建一个效果变量,以便我可以引用变量并设置它们的值,但出现了问题。我从 Frank Luna 的 Introduction to 3D Game Programming 中提取了一个 sn-p,并在必要时进行了调整

HRESULT hr;
DWORD shaderFlags = 0;
ID3D10Blob * compiledShader = 0;
ID3D10Blob * compilationMessages = 0;
hr = D3DX11CompileFromFile(L"cubemap.fx", 0, 0, 0, "fx_4_0", shaderFlags, 0, 0, &compiledShader, &compilationMessages, 0);
if (FAILED(hr))
{
    MessageBox(nullptr,
        L"Failed to compile cubemap shader D3DX11", L"Error", MB_OK);
    return hr;
}
ID3DX11Effect * shader;
hr = D3DX11CreateEffectFromMemory(
    compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 0, device, &shader);
if (FAILED(hr))
{
    MessageBox(nullptr,
        L"Could not create effect from memory", L"Error", MB_OK);
    return hr;
}

它会抛出错误

Could not create effect from memory

HR = E_FAIL

Attempted to create a device with the debug layer enabled and the layer is not installed.

我尝试调试了一下并重建效果库,但仍然没有。有人能发现问题或告诉我如何寻找原因吗?

编辑:我认为问题出在调试层。我尝试使用(D3D10 和 D3D11)启用调试层

#if defined(_DEBUG) || defined (DEBUG)
    shaderFlags |= D3D10_CREATE_DEVICE_DEBUG;
    shaderFlags |= D3D10_SHADER_DEBUG;
    shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif

我的设备标志也启用调试模式

    UINT createDeviceFlags = 0;

#if defined (_DEBUG) || defined(DEBUG)
    createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

我使用的是 Windows 8.1,而 Visual Studio 默认使用的是 Windows 8.1 SDK,但我还引用了 2010 年 6 月的旧 SDK,这就是问题所在。我上面尝试使用的方法来自旧的 SDK。

我相信所有需要的 dll 都已为调试层安装。

我还有旧 sdk 的 dll(我用来引用旧方法的那个)

已解决

我下载了最新版本的 Effects11,并使用兼容的 fx 版本 (fx_5_0) 编译了着色器

【问题讨论】:

  • 你没有告诉我们hr的确切值是什么。
  • 您的编辑仍然没有告诉我们hr 是什么:msdn.microsoft.com/en-us/library/windows/desktop/… FAILED 宏只告诉我们hr < 0
  • Attempted to create a device with the debug layer enabled and the layer is not installed. 那么实际错误的文本是否比FAILED(hr) 提供了更多细节?
  • @PaulMcKenzie 我对它进行了一些阅读并进行了一些修改,但它仍在发生。设备标志也启用调试模式。有什么我需要安装的吗?
  • 您应该首先从 GitHub 获取最新版本的 Effects 11。其次,确保您的项目使用正确的包含顺序来混合旧的旧版 DirectX SDK 和 Windows 8.1 SDK。见MSDN

标签: c++ directx


【解决方案1】:

提取最新版本的 Effects 11 似乎可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多