Page 1 of 1

Question to Material.getBestTechnique(...)

Posted: Sat Sep 27, 2014 7:38 pm
by phoenix_64

Material.getBestTechnique(...) may return NULL, if a material could not be successfully compiled.

Now in several places, OGRE depends on getBestTechnique() without checking for NULL, e.g.

Code: Select all

Technique* t = mat->getBestTechnique(0, *seci);
for (unsigned short p = 0; p < t->getNumPasses(); ++p)
SceneManager::validatePassForRendering(const Pass* pass)

Code: Select all

Technique* lateTech = pass->getParent()->getParent()->getBestTechnique();
if (lateTech->getNumPasses() <= pass->getIndex())
while in other places, getBestTechnique() is checked for NULL:


Code: Select all

Technique *technique = mMaterial->getBestTechnique();
if( technique )
Since a faulty material is a very common error, my questions are:
- Is it intended not to check at some places, e.g. due to performance reasons?
- If this is so, wouldn't it be better to throw directly, when a faulty material is detected? Currently, it is only logged* - but will lead to an inevitable crash in some situations. An instant throw would leave the causing material as the last message in the log, making it easier to find the problem.

*see Material::compile():

Code: Select all

if (mSupportedTechniques.empty())
     << "WARNING: material " << mName << " has no supportable "
     << "Techniques and will be blank. Explanation: \n" << mUnsupportedReasons;

Re: Question to Material.getBestTechnique(...)

Posted: Mon Sep 29, 2014 6:58 pm
by dark_sylinc
There are four things that can happen:
  • The "no supported technique" status is detected early. The material is never used because a fallback is used instead. So, no need to keep checking for null pointers.
  • The material is manually provided or absolutely necessary (i.e. no fallback is possible, as in the instancing case). We need to check for null pointers.
  • The "no supported technique" status is detected early. It throws but it isn't caught. Crash.
  • The "no supported technique" status is never detected. Null pointer is used. Crash.
The last two aren't that bad per-se. After all this is a fatal error in your data (i.e. malformed shader) you should seriously fix.