Game Development Community

CustomMaterial crash with missing shader

by David Wyand · in Torque Game Engine Advanced · 10/04/2004 (10:42 am) · 4 replies

Greetings!

I've discovered that if you've made a mistake in setting up a custom material you will get an engine crash.

In materials/customMaterial.cpp, here's a fix for missing shader data (changes in bold):

//--------------------------------------------------------------------------
// Sets up render states for a specific pass
//--------------------------------------------------------------------------
void CustomMaterial::setupSubPass( SceneGraphData &sgData )
{
   setBlendState( blendOp );

   // activate shader
   if( [b]mShaderData &&[/b] mShaderData->shader ) [b]//*** DAW: Added check[/b]
   {
      mShaderData->shader->process();
   }
   else
   {
      GFX->disableShaders();
      GFX->setTextureStageColorOp( mMaxTex, GFXTOPDisable );
   }

   setupStages( sgData );
}

This could be improved even further by including a Con::warnf() if the data is missing.

- LightWave Dave

About the author

A long time Associate of the GarageGames' community and author of the Torque 3D Game Development Cookbook. Buy it today from Packt Publishing!


#1
10/04/2004 (11:26 am)
Actually I would have said that the initialisation of mShaderData was at fault as mShaderData and all it's member pointers should be null if the shader isn't set.

If a crash is occuring then clearly mShaderData->shader contains garbage if no shader is found.
#2
10/04/2004 (11:33 am)
Greetings!

Peter, unless I've misunderstood what you meant, the case I've corrected for is indeed when mShaderData is NULL. The reason mShaderData->shader is crashing is because mShaderData is a NULL pointer.

Did you mean something else?

- LightWave Dave
#3
10/04/2004 (12:42 pm)
Nice catch but it seems to me that the best place to catch this would be before the structure is passed around.
#4
10/04/2004 (1:34 pm)
Greetings!

Yup, there may be a better place further up the chain to catch this. I'll leave that as an exercise for the reader.

Don't ya just hate that? :o)

Seriously though, this at least allowed me to get past an ill-defined custom material without a crash, which was good enough for the work I'm doing for IGC. After IGC, we can look to see where the most appropriate check point is if someone else hasn't found it.

- LightWave Dave