diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index 3c03c514..89a964b7 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -485,9 +485,11 @@ SGCloudLayer::rebuild() // repaint the cloud layer colors bool SGCloudLayer::repaint( const SGVec3f& fog_color ) { osg::Vec4f combineColor(toOsg(fog_color), cloud_alpha); - osg::TexEnvCombine* combiner - = dynamic_cast(layer_root->getStateSet() - ->getTextureAttribute(1, osg::StateAttribute::TEXENV)); + osg::StateAttribute* textureAtt = layer_root->getStateSet()->getTextureAttribute(1, osg::StateAttribute::TEXENV); + osg::TexEnvCombine* combiner = dynamic_cast(textureAtt); + + if (combiner == nullptr) + return false; combiner->setConstantColor(combineColor); // Set the fog color for the 3D clouds too.