Jump to content

  • Log In with Google      Sign In   
  • Create Account


Why does D3DX11CompileFromFile keep returning a NULL pointer?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 jiro27   Members   -  Reputation: 145

Like
0Likes
Like

Posted 23 September 2012 - 02:59 PM

Hi everyone, I'm really new to DirectX programming and I have been having a problem with the attached code, Attached File  drawTriangle.txt   9.74KB   40 downloads, where I am getting the error:
Unhandled exception at 0x777b15de in d3dDrawTriangle.exe: 0xC0000005: Access violation reading location 0x00000000.

I've narrowed the problem down to these lines:
// load and compile the two shaders
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

// encapsulate both shaders into shader objects
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

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. Any help would be amazing.
Also, here's the shader file I am using:
struct VOut
{
float4 position : SV_POSITION;
float4 color : COLOR;
};

VOut VShader(float4 position : POSITION, float4 color : COLOR)
{
VOut output;

output.position = position;
output.color = color;

return output;
}


float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7812

Like
1Likes
Like

Posted 23 September 2012 - 03:32 PM

If you take your VErrorMessage and PErrorMessage blobs, call GetBufferPointer on them and cast the result to "char *" it will tell you what went wrong. Most probable is that it can't find the files you specify.
char *verror = (char *) VErrorMessage->GetBufferPointer ();

char *perror = (char *) PErrorMessage->GetBufferPointer ();

Edited by mhagain, 23 September 2012 - 03:33 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 jiro27   Members   -  Reputation: 145

Like
0Likes
Like

Posted 23 September 2012 - 07:55 PM

If you take your VErrorMessage and PErrorMessage blobs, call GetBufferPointer on them and cast the result to "char *" it will tell you what went wrong. Most probable is that it can't find the files you specify.

Alright, I did that, and the char on both Error Messages results to this:
= CXX0030: Error: expression cannot be evaluated
I don't really get what that means, and I have moved the shaders.hlsl file into the project file, but that hasn't helped. I'm still stuck...

#4 Nik02   Crossbones+   -  Reputation: 2766

Like
0Likes
Like

Posted 24 September 2012 - 12:01 AM

If you provide the file name but not the path, the file is expected to be in the same directory as the executable. The file being included in the project does not in any way guarantee this.

A robust way is to get the path of the executable using GetModuleFileName (, strip the exe file name from that), and concatenate it with the shader file name.

The error blobs do not catch "file not found", because the errors are written by the compiler after it actually gets to work on a found file data.

Niko Suni


#5 eppo   Crossbones+   -  Reputation: 2360

Like
0Likes
Like

Posted 24 September 2012 - 07:50 AM

Have you ever checked the return code (HRESULT) of the D3DX11CompileFromFile() call?

If it's unclear whether the FromFile() methods even know where to find the files in the first place, you should use a custom loader for the hlsl data. First make sure the data is available, then pass it to D3DX11CompileFromMemory.

Edited by eppo, 24 September 2012 - 07:52 AM.


#6 jiro27   Members   -  Reputation: 145

Like
0Likes
Like

Posted 25 September 2012 - 01:01 PM

Alright, maybe I need to first ask how I properly add a shader file to VC++ 2010 in the first place, as this might be the main problem.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS