Jump to content
  • Advertisement
Sign in to follow this  
Rasenger

Strange access violation problem

This topic is 4139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to use shaders with C++ / DX9. Creating vertex shader works but creating pixel shader doesn't. I get "access violation reading ... 0x000000 blaa blaa"-error here:
d3ddev->CreatePixelShader((DWORD*)code2->GetBufferPointer(), &pixelShader);
Here's some code from my terrain class:
LPDIRECT3DVERTEXDECLARATION9 vertexDeclaration;
LPDIRECT3DVERTEXSHADER9 vertexShader;
LPD3DXCONSTANTTABLE constantTable;
LPDIRECT3DPIXELSHADER9 pixelShader;

...

// Now were're in constructor

vertexDeclaration = NULL;
vertexShader = NULL;
pixelShader = NULL;
constantTable = NULL;

...

/* Vertex declaration */

D3DVERTEXELEMENT9 decl[] = {
	{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
    {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
    D3DDECL_END()};

d3ddev->CreateVertexDeclaration(decl, &vertexDeclaration);

/* Load shaders */

HRESULT result1 = NULL;
HRESULT result2 = NULL;
LPD3DXBUFFER code1 = NULL;
LPD3DXBUFFER code2 = NULL;

//set up Vertex Shader
result1 = D3DXCompileShaderFromFile(L"TerrainVertex.fx",
                                   NULL,
                                   NULL,
                                   "vs_main",
                                   "vs_1_1",
                                   0,
                                   &code1,
                                   NULL,
                                   &constantTable);

d3ddev->CreateVertexShader((DWORD*)code1->GetBufferPointer(), &vertexShader);
code1->Release();

//set up Pixel Shader
result2 = D3DXCompileShaderFromFile(L"TerrainPixel.fx",
                                   NULL,     
                                   NULL,
                                   "ps_main",
                                   "ps_1_1",
                                   0,
                                   &code2,
                                   NULL,
                                   NULL);

/* ||||||  NEXT LINE PRODUCES ACCESS VIOLATION ERROR |||||| */
d3ddev->CreatePixelShader((DWORD*)code2->GetBufferPointer(), &pixelShader);
code2->Release();

Share this post


Link to post
Share on other sites
Advertisement
Are you sure the return values from all the previous functions indicate success? You don't seem to be doing any checking in your code.

Share this post


Link to post
Share on other sites
Well I added assertions there (should've done it earlier -__-) and it seems there's something wrong with this:


//set up Pixel Shader
result2 = D3DXCompileShaderFromFile(L"TerrainPixel.fx",
NULL,
NULL,
"ps_main",
"ps_1_1",
0,
&code2,
NULL,
NULL);


I've checked that the filename is correct, also the HLSL file _should_ be OK. Hmm..

Share this post


Link to post
Share on other sites
Well, which error did it give? It should be one of D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA, or E_OUTOFMEMORY.

Share this post


Link to post
Share on other sites
How would I know? :DDDDD Yes, I'm so fucking noob I shouldn't exist but I do and please bear with it. :D

Share this post


Link to post
Share on other sites
There are lots of ways. You can set a breakpoint on the line in the debugger and examine the value directly after the call. You can print the value to a file. You can display the value with a MessageBox call.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rasenger

//set up Pixel Shader
result2 = D3DXCompileShaderFromFile(L"TerrainPixel.fx",
NULL,
NULL,
"ps_main",
"ps_1_1",
0,
&code2,
NULL,
NULL);


I've checked that the filename is correct, also the HLSL file _should_ be OK. Hmm..
Well "should be ok" is nice to say, but evidence would suggest you are wrong [wink]

Running FX files against fxc.exe on the command line or creating a custom build step in VS is a convenient way of checking this. You can get VS to compile each FX file when you compile the rest of your app and it'll catch the errors the same as with any other code...

Alternatively, just refer to your documentation and set your penultimate 'NULL' parameter to be a LPD3DXBUFFER and pass it to OutputDebugStringA() and you'll get a list of the errors during compilation. This should be as standard as checking the return codes.

hth
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!