所以我有以下代码:
extern ID3D11Device* dev;
extern ID3D11DeviceContext* devcon;
//shaders
ID3D10Blob *VS, *PS, *error;
HRESULT r;
error = 0;
r = D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", D3DCOMPILE_DEBUG, 0, 0, &VS, &error, 0);
if(FAILED(r))
{
LPCWSTR errmsg = (LPCWSTR)error->GetBufferPointer();
MessageBox(hWnd, errmsg, L"error", MB_OK);
return;
}
error = 0;
r = D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "PShader", "ps_5_0", D3DCOMPILE_DEBUG, 0, 0, &PS, &error, 0);
if(FAILED(r))
{
LPCWSTR errmsg = (LPCWSTR)error->GetBufferPointer();
MessageBox(hWnd, errmsg, L"error", MB_OK);
return;
}
// encapsulate both shaders into shader objects
r = dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &vertexShader);
r = dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pixelShader);
devcon->VSSetShader(this->vertexShader, 0, 0);
devcon->PSSetShader(this->pixelShader, 0, 0);
运行代码,D3DX11CompileFromFile
对于顶点着色器和像素着色器都返回S_OK
,但是当代码命中CreateVertexShader()
它时会引发访问冲突,对于我来说,我无法弄清楚为什么。我可能做了一些相当愚蠢的事情,我似乎无法弄清楚。