I can't be the only one...

Started by
11 comments, last by battle_bright 15 years, 8 months ago
Is anyone else having trouble with programs that use effects files (.fx) crashing when you try to run it? After compiling it using Visual C++ Express 2008? I can't even get a simple vertex shader to run. I have no idea why my program is crashing! I can't be the only one who's had this problem.
Advertisement
If you're program is crashing, the first step is to figure out where it's crashing. This should be easy: when you get the "unhandled exception" dialog, look at the call stack and go to the last function called in your actual code. Then if you'd like, you can paste some of that relevant code here (along with the error message) and we can try to help you out.
Quote:Original post by MJP
If you're program is crashing, the first step is to figure out where it's crashing. This should be easy: when you get the "unhandled exception" dialog, look at the call stack and go to the last function called in your actual code. Then if you'd like, you can paste some of that relevant code here (along with the error message) and we can try to help you out.


The program is set to run full screen so I haven't seen the "unhandled exception dialog". Would I be able to see that if I ran the program windowed? I'm actually beginning to think the problem is with the implementation of the program itself. I've been able to compile and run other programs that use effects files with no problem at all. I'm completely new to real time 3d programming and I'm trying to teach myself. It just sucks because this was the simplest example of writing a vertex shader that I could find and it doesn't work. For me at least. I'll try running the program windowed and stepping through it with the debugger.
Not sure what this means:
Unhandled exception at 0x002618ad in Lesson_4_Loading_Lights.exe: 0xC0000005: Access violation reading location 0x00000000.
...Googling as we speak...

It seems to be choking on the call to:
effect->FindNextValidTechnique(NULL, &technique);

 // load the effect file    D3DXCreateEffectFromFile(d3ddev, L"dxtshader_4.fx", 0, 0, 0, 0, &effect, &errorlog);    // find the best technique    effect->FindNextValidTechnique(NULL, &technique);
I think I'm gonna play around with some of the flags in the D3DXCreateEffectFromFile() function.
When I comment out the call to FindNextValidTechnique(), the program gives me another exception here:

effect->SetFloatArray("LightPos", &vecPosition.x, 3);


So am I getting these errors because I'm trying to access areas of memory that are unavailable?
It looks like effect is NULL. Try checking the error code returned by D3DXCreateEffectFromFile
I'll try checking D3DXCreateEffectFromFile. Could someone give me an example of failure code to run for use with the FAILED() macro? I haven't done very much debugging.
Well, its very easy. The function failed if the effect is zero afterwards. If you want more details, you can use this code:
// First, we create a buffer that should contain the compilation errorsLPD3DXBUFFER pBuff;int ret = D3DXCreateBuffer( 2048, &pBuff );if( ret != D3D_OK )	pBuff = NULL;// Then we create the effect// Don't care about the exact params I used here, I don't load the shader directly from the harddisk, but from memory// The important thing is, that the last parameter is of type LPD3DXBUFFER*D3DXCreateEffect( g_pd3dDevice,		  buff.data(),		  buff.getsize(),		  0, 		  0,		  0,		  0,		  &m_pEffect,	          &pBuff );if( m_pEffect == NULL ){	if( pBuff != NULL )	{		// Now you can cast this bugger to an pointer to char		// Wich you then can access as you like (print it for example)		std::string buffer = static_cast<char*>( pBuff->GetBufferPointer() );	}}
Quote:Original post by SiS-Shadowman
Well, its very easy. The function failed if the effect is zero afterwards. If you want more details, you can use this code:
*** Source Snippet Removed ***
Never check return values like that. You're checking one of the 2 billion possible success codes there, some functions return codes other than D3D_OK for success. Also, the return type from D3DXCreateBuffer is HRESULT, not int (HRESULT is unsigned) (EDIT: It's not unsigned, but it is a long, not an int - which could be a different size). The following is much more safe:

// First, we create a buffer that should contain the compilation errorsLPD3DXBUFFER pBuff;HRESULT hr = D3DXCreateBuffer( 2048, &pBuff );if(FAILED(hr))	pBuff = NULL;// Then we create the effect// Don't care about the exact params I used here, I don't load the shader directly from the harddisk, but from memory// The important thing is, that the last parameter is of type LPD3DXBUFFER*hr = D3DXCreateEffect( g_pd3dDevice,		  buff.data(),		  buff.getsize(),		  0, 		  0,		  0,		  0,		  &m_pEffect,	          &pBuff );if( FAILED(hr)){	if( pBuff != NULL )	{		// Now you can cast this bugger to an pointer to char		// Wich you then can access as you like (print it for example)		std::string buffer = static_cast<char*>( pBuff->GetBufferPointer() );	}}
It's also perfectly safe to assume that m_pEffect is valid if D3DXCreateEffect succeeds, so you should check for failure of the function, not it setting a parameter to null.

[Edited by - Evil Steve on August 13, 2008 5:18:49 AM]

This topic is closed to new replies.

Advertisement