我有这个奇怪的错误,无法找到解决方法。 我正在尝试创建一个顶点和像素着色器,但是当我用CreateVertexShader和CreatePixelShader调用它时,它返回NULL。我将着色器类型设置为fx,并将着色器模型设置为5_0。 我在Windows 10上使用Visual Studio 2015
创建时:
ID3D11Buffer* TriangleVertBuffer;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob *VS_Buffer;
ID3D10Blob *PS_Buffer;
ID3D11InputLayout* VertLayout;
当我打电话给他们时:
//Compile Shaders from shader file
hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "VS", "Vs_5_0", 0, 0, &VS_Buffer, 0);
hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "PS", "Ps_5_0", 0, 0, &PS_Buffer, 0);
//Create shader objects
hr = D3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS);
hr = D3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS);
My Effects.fx class
float4 VS(float4 inPos : POSITION) : SV_POSITION
{
return inPos;
}
float4 PS() : SV_TARGET
{
return float4(0.0f, 0.0f, 1.0f, 1.0f);
}
当我运行它时,它不会出现错误,只会出现断点
AzuraEngine.exe中的0x00007FF71F191AC4抛出异常:0xC0000005: 访问冲突读取位置0x0000000000000000。
并且调试说:
- VS_Buffer 0x0000000000000000 ID3D10Blob *
- & PS_Buffer 0x00007ff71f19f1f0 {AzuraEngine.exe!ID3D10Blob * PS_Buffer} {0x0000000000000000} ID3D10Blob * *
- & VS 0x00007ff71f19f1d8 {AzuraEngine.exe!ID3D11VertexShader * VS} {0x0000000000000000} ID3D11VertexShader * * D3DCompileFromFile 0x00007ff71f192950 {AzuraEngine.exe!D3DCompileFromFile} void *
- D3d11Device 0x000000c9ab0c78c0 ID3D11Device * hr 0x8876086c HRESULT
源脚本:
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3d10.lib")
#pragma comment(lib, "D3DCompiler.lib")
#include <Windows.h>
#include <d3d11.h>
#include <d3d10.h>
#include <DirectXMath.h>
#include <d3dcompiler.h>
using namespace DirectX;
bool InitScene();
HRESULT hr;
ID3D11Device* D3d11Device;
//Creating all variables to the shader
ID3D11Buffer* TriangleVertBuffer;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob *VS_Buffer;
ID3D10Blob *PS_Buffer;
ID3D11InputLayout* VertLayout;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
if (!InitScene())
{
return 0;
}
return 0;
}
bool InitScene()
{
//Compile shader from file
hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "VS", "Vs_5_0", 0, 0, &VS_Buffer, 0);
hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "PS", "Ps_5_0", 0, 0, &PS_Buffer, 0);
//Creating Verex and Pixel shader
hr = D3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS);
hr = D3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS);
return true;
}