From a51e95222d8cc974771382026445c7642d32c812 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 28 Jan 2009 09:21:46 +0000 Subject: [PATCH] From Patrick Hartling, "I encountered a bug related to RTTI for subclasses of osg::Shape. The circumstances under which this bug occur are rather specific, but the basic problem occurs when one translation unit other than libosg.so constructs an object that is a subclass of osg::Shape and another translation unit other than libosg.so tries to perform a dynamic_cast or other RTTI-based operation on that object. Under these circumstances, the RTTI operation will fail. In my case, the translation units involved were an application and osgdb_ive.so. The application constructed a scene graph that included instantiations of subclasses of osg::Shape. Depending on how the user ran the application, it would write the scene graph to an IVE file using osgDB::writeNodeFile(). The dynamic_cast operations in DataOutputStream::writeShape() would fail on the first subclass of osg::Shape that was encountered. This is because there were two different RTTI data objects for all osg::Shape subclasses being compared: one in the application and one in osgdb_ive.so. The fix for this is simple. We must ensure that at least one member function of each of the subclasses of the polymorphic type osg::Shape is compiled into libosg.so so that there is exactly one RTTI object for that type in libosg.so. Then, all code linking against libosg.so will use that single RTTI object. The following message from a list archive sort of explains the issue and the solution: http://aspn.activestate.com/ASPN/Mail/Message/1688156 While the posting has to do with Boost.Python, the problem applies to C++ libraries in general." --- include/osg/Shape | 44 ++++++++++++++++++++++---------------------- src/osg/Shape.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 22 deletions(-) diff --git a/include/osg/Shape b/include/osg/Shape index 1b8cee092..b532edca6 100644 --- a/include/osg/Shape +++ b/include/osg/Shape @@ -99,12 +99,12 @@ class HeightField; class CompositeShape; -class ShapeVisitor +class OSG_EXPORT ShapeVisitor { public: ShapeVisitor() {} - virtual ~ShapeVisitor() {} + virtual ~ShapeVisitor(); virtual void apply(Shape&) {} virtual void apply(Sphere&) {} @@ -121,12 +121,12 @@ class ShapeVisitor virtual void apply(CompositeShape&) {} }; -class ConstShapeVisitor +class OSG_EXPORT ConstShapeVisitor { public: ConstShapeVisitor() {} - virtual ~ConstShapeVisitor() {} + virtual ~ConstShapeVisitor(); virtual void apply(const Shape&) {} virtual void apply(const Sphere&) {} @@ -143,7 +143,7 @@ class ConstShapeVisitor virtual void apply(const CompositeShape&) {} }; -class Sphere : public Shape +class OSG_EXPORT Sphere : public Shape { public: @@ -178,14 +178,14 @@ class Sphere : public Shape protected: - virtual ~Sphere() {} + virtual ~Sphere(); Vec3 _center; float _radius; }; -class Box : public Shape +class OSG_EXPORT Box : public Shape { public: @@ -230,7 +230,7 @@ class Box : public Shape protected: - virtual ~Box() {} + virtual ~Box(); Vec3 _center; Vec3 _halfLengths; @@ -240,7 +240,7 @@ class Box : public Shape -class Cone : public Shape +class OSG_EXPORT Cone : public Shape { public: @@ -291,7 +291,7 @@ class Cone : public Shape protected: - virtual ~Cone() {} + virtual ~Cone(); Vec3 _center; float _radius; @@ -300,7 +300,7 @@ class Cone : public Shape Quat _rotation; }; -class Cylinder : public Shape +class OSG_EXPORT Cylinder : public Shape { public: @@ -348,7 +348,7 @@ class Cylinder : public Shape protected: - virtual ~Cylinder() {} + virtual ~Cylinder(); Vec3 _center; float _radius; @@ -356,7 +356,7 @@ class Cylinder : public Shape Quat _rotation; }; -class Capsule : public Shape +class OSG_EXPORT Capsule : public Shape { public: @@ -404,7 +404,7 @@ class Capsule : public Shape protected: - virtual ~Capsule() {} + virtual ~Capsule(); Vec3 _center; float _radius; @@ -412,7 +412,7 @@ class Capsule : public Shape Quat _rotation; }; -class InfinitePlane : public Shape, public Plane +class OSG_EXPORT InfinitePlane : public Shape, public Plane { public: InfinitePlane() {} @@ -425,10 +425,10 @@ class InfinitePlane : public Shape, public Plane protected: - virtual ~InfinitePlane() {} + virtual ~InfinitePlane(); }; -class TriangleMesh : public Shape +class OSG_EXPORT TriangleMesh : public Shape { public: @@ -453,14 +453,14 @@ class TriangleMesh : public Shape protected: - ~TriangleMesh() {} + virtual ~TriangleMesh(); ref_ptr _vertices; ref_ptr _indices; }; -class ConvexHull : public TriangleMesh +class OSG_EXPORT ConvexHull : public TriangleMesh { public: @@ -473,7 +473,7 @@ class ConvexHull : public TriangleMesh protected: - ~ConvexHull() {} + virtual ~ConvexHull(); }; class OSG_EXPORT HeightField : public Shape @@ -583,7 +583,7 @@ class OSG_EXPORT HeightField : public Shape typedef HeightField Grid; -class CompositeShape : public Shape +class OSG_EXPORT CompositeShape : public Shape { public: @@ -637,7 +637,7 @@ class CompositeShape : public Shape protected: - ~CompositeShape() {} + virtual ~CompositeShape(); ref_ptr _shape; ChildList _children; diff --git a/src/osg/Shape.cpp b/src/osg/Shape.cpp index 2aafaf376..8b90d9f1a 100644 --- a/src/osg/Shape.cpp +++ b/src/osg/Shape.cpp @@ -19,6 +19,46 @@ Shape::~Shape() { } +ShapeVisitor::~ShapeVisitor() +{ +} + +ConstShapeVisitor::~ConstShapeVisitor() +{ +} + +Sphere::~Sphere() +{ +} + +Box::~Box() +{ +} + +Cone::~Cone() +{ +} + +Cylinder::~Cylinder() +{ +} + +Capsule::~Capsule() +{ +} + +InfinitePlane::~InfinitePlane() +{ +} + +TriangleMesh::~TriangleMesh() +{ +} + +ConvexHull::~ConvexHull() +{ +} + HeightField::HeightField(): _columns(0), _rows(0), @@ -129,4 +169,7 @@ Vec2 HeightField::getHeightDelta(unsigned int c,unsigned int r) const return heightDelta; } +CompositeShape::~CompositeShape() +{ +}