From 640b03b671ba9cef68a50c822ae8a8531b4806a9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 13 May 2018 11:52:06 +0100 Subject: [PATCH] Fixed crash when using ShapeDrawable with a TriangleMesh or ConvexHull shape due to missing texture coords --- include/osg/Shape | 11 +++++++---- src/osg/Shape.cpp | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/osg/Shape b/include/osg/Shape index 7d856bee2..5f46036bd 100644 --- a/include/osg/Shape +++ b/include/osg/Shape @@ -768,10 +768,13 @@ class OSG_EXPORT BuildShapeGeometryVisitor : public ConstShapeVisitor virtual void apply(const CompositeShape&); void Normal(const Vec3f& v) { _normals->push_back(v); } - void Normal3f(float x, float y, float z) { _normals->push_back(Vec3(x,y,z)); } - void TexCoord2f(float x, float y) { _texcoords->push_back(Vec2(x,y)); } - void Vertex(const Vec3f& v) { _vertices->push_back(v); } - void Vertex3f(float x, float y, float z) { _vertices->push_back(Vec3(x,y,z)); } + void Normal3f(float x, float y, float z) { Normal(Vec3(x,y,z)); } + + void TexCoord(const Vec2f& tc) { _texcoords->push_back(tc); } + void TexCoord2f(float x, float y) { TexCoord(Vec2(x,y)); } + + void Vertex(const Vec3f& v); + void Vertex3f(float x, float y, float z) { Vertex(Vec3(x,y,z)); } void setMatrix(const Matrixd& m); diff --git a/src/osg/Shape.cpp b/src/osg/Shape.cpp index d91df88af..9dc01fb03 100644 --- a/src/osg/Shape.cpp +++ b/src/osg/Shape.cpp @@ -233,6 +233,20 @@ void BuildShapeGeometryVisitor::setMatrix(const Matrixd& m) _inverse.setTrans(0.0,0.0,0.0); } +void BuildShapeGeometryVisitor::Vertex(const Vec3f& v) +{ + _vertices->push_back(v); + if (_normals.valid() && _normals->size()<_vertices->size()) + { + while(_normals->size()<_vertices->size()) _normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f)); + } + if (_texcoords.valid() && _texcoords->size()<_vertices->size()) + { + while(_texcoords->size()<_vertices->size()) _texcoords->push_back(osg::Vec2(0.0f, 0.0f)); + } +} + + void BuildShapeGeometryVisitor::Begin(GLenum mode) { _mode = mode;