1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 06:23:52 +00:00

Don't add empty PrimitiveSets (prevent undefined behaviour)

This commit is contained in:
AnyOldName3 2020-04-18 02:38:20 +01:00
parent 4167bdf319
commit 1cf2036386

View file

@ -85,6 +85,8 @@ namespace SceneUtil
osg::ref_ptr<osg::Geometry> gridGeometry = new osg::Geometry(); osg::ref_ptr<osg::Geometry> gridGeometry = new osg::Geometry();
if (PointIndexCount || EdgeIndexCount)
{
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(VertexCount); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(VertexCount);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(ColorCount); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(ColorCount);
osg::ref_ptr<osg::DrawElementsUShort> pointIndices = osg::ref_ptr<osg::DrawElementsUShort> pointIndices =
@ -166,10 +168,12 @@ namespace SceneUtil
gridGeometry->setVertexArray(vertices); gridGeometry->setVertexArray(vertices);
gridGeometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX); gridGeometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
if (PointIndexCount)
gridGeometry->addPrimitiveSet(pointIndices); gridGeometry->addPrimitiveSet(pointIndices);
if (EdgeIndexCount)
gridGeometry->addPrimitiveSet(lineIndices); gridGeometry->addPrimitiveSet(lineIndices);
gridGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); gridGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
}
return gridGeometry; return gridGeometry;
} }
@ -184,6 +188,8 @@ namespace SceneUtil
osg::ref_ptr<osg::Geometry> wireframeGeometry = new osg::Geometry(); osg::ref_ptr<osg::Geometry> wireframeGeometry = new osg::Geometry();
if (IndexCount)
{
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(VertexCount); osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(VertexCount);
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(ColorCount); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(ColorCount);
osg::ref_ptr<osg::DrawElementsUShort> indices = osg::ref_ptr<osg::DrawElementsUShort> indices =
@ -221,7 +227,7 @@ namespace SceneUtil
wireframeGeometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX); wireframeGeometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
wireframeGeometry->addPrimitiveSet(indices); wireframeGeometry->addPrimitiveSet(indices);
wireframeGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); wireframeGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
}
return wireframeGeometry; return wireframeGeometry;
} }