diff --git a/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx b/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx
index c28e89a3f63c1bf057e2b6147aca959ae5ad8e7b..6556dbdba3f8410a8ad10c09615b72bf00e0bf33 100644
--- a/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx
+++ b/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx
@@ -1688,8 +1688,15 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderTCoord(
          << tcoordname << "VCVSOutput" << tCoordImpFSPost << "); // Read texture color\n";
     }
 
+    vtkTextureObject* textureObject = vtkOpenGLTexture::SafeDownCast(texture)->GetTextureObject();
+    if (!textureObject)
+    {
+      vtkErrorMacro("Could not find the vtkTextureObject");
+      return;
+    }
+
     // Update color based on texture number of components
-    int tNumComp = vtkOpenGLTexture::SafeDownCast(texture)->GetTextureObject()->GetComponents();
+    int tNumComp = textureObject->GetComponents();
     switch (tNumComp)
     {
       case 1: