File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,26 @@ bool OgreMeshFactory::LoadImpl(const MeshDescriptor &_desc)
231231 continue ;
232232 }
233233
234+ // todo(iche033) use SubMesh::HasValidIndices() when gz-common 6.0.3
235+ // is released
236+ bool validIndices = true ;
237+ for (unsigned int j = 0u ; j < s->IndexCount (); ++j)
238+ {
239+ int index = s->Index (j);
240+ if (index > 0 && static_cast <unsigned int >(index) >= s->VertexCount ())
241+ {
242+ validIndices = false ;
243+ break ;
244+ }
245+ }
246+ if (!validIndices)
247+ {
248+ gzwarn << " Mesh[" << _desc.mesh ->Name () << " ] submesh[" << s->Name ()
249+ << " ] has invalid indices. Skipping submesh creation."
250+ << std::endl;
251+ continue ;
252+ }
253+
234254 Ogre::SubMesh *ogreSubMesh;
235255 Ogre::VertexData *vertexData;
236256 Ogre::VertexDeclaration* vertexDecl;
Original file line number Diff line number Diff line change @@ -286,6 +286,26 @@ bool Ogre2MeshFactory::LoadImpl(const MeshDescriptor &_desc)
286286 continue ;
287287 }
288288
289+ // todo(iche033) use SubMesh::HasValidIndices() when gz-common 6.0.3
290+ // is released
291+ bool validIndices = true ;
292+ for (unsigned int j = 0u ; j < s->IndexCount (); ++j)
293+ {
294+ int index = s->Index (j);
295+ if (index > 0 && static_cast <unsigned int >(index) >= s->VertexCount ())
296+ {
297+ validIndices = false ;
298+ break ;
299+ }
300+ }
301+ if (!validIndices)
302+ {
303+ gzwarn << " Mesh[" << _desc.mesh ->Name () << " ] submesh[" << s->Name ()
304+ << " ] has invalid indices. Skipping submesh creation."
305+ << std::endl;
306+ continue ;
307+ }
308+
289309 Ogre::v1::SubMesh *ogreSubMesh;
290310 Ogre::v1::VertexData *vertexData;
291311 Ogre::v1::VertexDeclaration* vertexDecl;
You can’t perform that action at this time.
0 commit comments