diff --git a/src/systems/collada_world_exporter/ColladaWorldExporter.cc b/src/systems/collada_world_exporter/ColladaWorldExporter.cc index 98b7a23568..463b91be0a 100644 --- a/src/systems/collada_world_exporter/ColladaWorldExporter.cc +++ b/src/systems/collada_world_exporter/ColladaWorldExporter.cc @@ -228,14 +228,20 @@ class ignition::gazebo::systems::ColladaWorldExporterPrivate { auto subMeshLock = mesh->SubMeshByIndex(k).lock(); subm = worldMesh.AddSubMesh(*subMeshLock.get()); - addSubmeshFunc(subMeshLock->MaterialIndex()); + if (const auto subMeshIdx = subMeshLock->GetMaterialIndex()) + addSubmeshFunc(static_cast(subMeshIdx.value())); + else + addSubmeshFunc(-1); } } else { auto subMeshLock = mesh->SubMeshByName(subMeshName).lock(); subm = worldMesh.AddSubMesh(*subMeshLock.get()); - addSubmeshFunc(subMeshLock->MaterialIndex()); + if (const auto subMeshIdx = subMeshLock->GetMaterialIndex()) + addSubmeshFunc(static_cast(subMeshIdx.value())); + else + addSubmeshFunc(-1); } } else