Skip to content

Commit 6f1ee65

Browse files
Add sanity check for valid submesh indices (#1123) (#1125)
(cherry picked from commit ef1d5a1) Signed-off-by: Ian Chen <[email protected]> Co-authored-by: Ian Chen <[email protected]>
1 parent 107007b commit 6f1ee65

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

ogre/src/OgreMeshFactory.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

ogre2/src/Ogre2MeshFactory.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)