# I can't be the only one...

## Recommended Posts

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.

##### Share on other sites
MJP    19755
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.

##### Share on other sites
Quote:
 Original post by MJPIf 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.

##### Share on other sites
Not sure what this means:
...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);

##### Share on other sites
I think I'm gonna play around with some of the flags in the D3DXCreateEffectFromFile() function.

##### Share on other sites
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?

##### Share on other sites
jaafit    116
It looks like effect is NULL. Try checking the error code returned by D3DXCreateEffectFromFile

##### Share on other sites
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.

##### Share on other sites
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() );	}}

##### Share on other sites
Evil Steve    2017
Quote:
 Original post by SiS-ShadowmanWell, 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]

##### Share on other sites
jollyjeffers    1570
Quote:
 Original post by battle_brightI haven't done very much debugging.
I can't begin to stress enough how essential debugging skills are. Writing code is probably one of the least difficult parts in the long run - being able to test, debug and reason about your software and its behaviour is often vastly more challenging and will often be a good indicator of a mediocre versus exceptional developer.

Read this and make sure you're familiar with every bit of it. Once you've got the basics you'll have more than enough opportunities to practice [wink]

hth
Jack

##### Share on other sites
Mike nl    390
Quote:
 Original post by Evil Steve*** Source Snippet Removed *** 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.

AFAIK, D3DXCreateEffect creates and sets the ID3DXBuffer* argument (it IS marked as out in the docs), no need to create the buffer yourself. Just Release() it afterwards.

##### Share on other sites
Wow! Thanks for all the information. There don't seem to be very many resources available about debugging. Especially when it comes to using the debugging tools that come with an SDK or in Visual C++. I didn't notice the stickies at the top of the forum about how to solve a problem yourself. I probably should have read through that earlier. There's also a cool FAQ with a link to setting up the DirectX SDK for better debugging that I didn't notice till later either.

Thanks a lot you guys, I think I'm gonna spend some time on the Intro to Debugging article.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account