From b4f54651f8920933c6780bcdc7c19349fe760ac6 Mon Sep 17 00:00:00 2001 From: capostrophic Date: Thu, 8 Aug 2019 15:41:09 +0300 Subject: [PATCH] Make sure strips have valid size --- components/nifbullet/bulletnifloader.cpp | 2 +- components/nifosg/nifloader.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index a33374ff5..7cfdbf40f 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -63,7 +63,7 @@ void fillTriangleMeshWithTransform(btTriangleMesh& mesh, const Nif::NiTriStripsD // Assume every strip has the same size const int singleStripSize = static_cast(strips[0].size()); - // Can't make a triangle from 2 vertices or less. + // Can't make a triangle from less than three vertices. if (singleStripSize < 3) return; diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 95f5fabf9..0e3c63515 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1128,6 +1128,10 @@ namespace NifOsg { for (const std::vector& strip : data->strips) { + // Can't make a triangle from less than three vertices. + // All strips have the same size. + if (strip.size() < 3) + break; geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP, strip.size(), (unsigned short*)strip.data())); }