Original Post
Hi everyone, I'm really new to DirectX programming and I have been having a problem with the attached code, [attachment=11424:drawTriangle.txt], where I am getting the error:
Unhandled exception at 0x777b15de in d3dDrawTriangle.exe: 0xC0000005: Access violation reading location 0x00000000.
[font=arial, helvetica, sans-serif]I've narrowed the problem down to these lines:[/font]
[font=courier new,courier,monospace] // load and compile the two shaders[/font]
[font=courier new,courier,monospace] ID3D10Blob *VS, *PS;
ID3D10Blob *VErrorMessage, *PErrorMessage;
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, &VErrorMessage, 0); // for some reason this is returning a NULL pointer for &VS
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "PShader", "ps_5_0", 0, 0, 0, &PS, &PErrorMessage, 0); // for some reason this is returning s NULL pointer for &PS[/font]
[font=courier new,courier,monospace] // encapsulate both shaders into shader objects
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);[/font]
[font=arial, helvetica, sans-serif]After some research I figured out that for some reason, D3DX11CompileFromFile is returning a NULL pointer, so when it tries to use VS, and I'm assuming PS, it is NULL, and thus doesn't work. I've tried updating my graphics card driver, but that hasn't helped, and I have no idea how to fix this problem. [/font][font=arial, helvetica, sans-serif]Any help would be amazing.[/font]
[font=arial, helvetica, sans-serif]Also, here's the shader file I am using:[/font]
struct VOut
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace]{
float4 position : SV_POSITION;
float4 color : COLOR;
};[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace]VOut VShader(float4 position : POSITION, float4 color : COLOR)
{
VOut output;[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace] output.position = position;
output.color = color;[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace] return output;
}[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace]float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}[/font][/font]
Unhandled exception at 0x777b15de in d3dDrawTriangle.exe: 0xC0000005: Access violation reading location 0x00000000.
[font=arial, helvetica, sans-serif]I've narrowed the problem down to these lines:[/font]
[font=courier new,courier,monospace] // load and compile the two shaders[/font]
[font=courier new,courier,monospace] ID3D10Blob *VS, *PS;
ID3D10Blob *VErrorMessage, *PErrorMessage;
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, &VErrorMessage, 0); // for some reason this is returning a NULL pointer for &VS
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "PShader", "ps_5_0", 0, 0, 0, &PS, &PErrorMessage, 0); // for some reason this is returning s NULL pointer for &PS[/font]
[font=courier new,courier,monospace] // encapsulate both shaders into shader objects
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);[/font]
[font=arial, helvetica, sans-serif]After some research I figured out that for some reason, D3DX11CompileFromFile is returning a NULL pointer, so when it tries to use VS, and I'm assuming PS, it is NULL, and thus doesn't work. I've tried updating my graphics card driver, but that hasn't helped, and I have no idea how to fix this problem. [/font][font=arial, helvetica, sans-serif]Any help would be amazing.[/font]
[font=arial, helvetica, sans-serif]Also, here's the shader file I am using:[/font]
struct VOut
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace]{
float4 position : SV_POSITION;
float4 color : COLOR;
};[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace]VOut VShader(float4 position : POSITION, float4 color : COLOR)
{
VOut output;[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace] output.position = position;
output.color = color;[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace] return output;
}[/font][/font]
[font=arial, helvetica, sans-serif][font=courier new,courier,monospace]float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}[/font][/font]