Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods,

forcing users to use osgDB::readRef*File() methods.  The later is preferable as it closes a potential threading bug when using paging databases in conjunction
with the osgDB::Registry Object Cache.  This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only
a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another
thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero.  Using osgDB::readREf*File() makes sure the a ref_ptr<> is
passed back and the referenceCount never goes to zero.

To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File()
usage.  The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of
templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group:

    bool addChild(Node* child); // old method which can only be used with a Node*

    tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method

These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache
and multi-threaded loaded more robust.



git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-10-22 13:42:19 +00:00
parent 79fb9abbbf
commit dd996a3289
295 changed files with 2503 additions and 2172 deletions

View File

@@ -212,6 +212,8 @@ class OSG_EXPORT Node : public Object
/** Set update node callback, called during update traversal. */
void setUpdateCallback(Callback* nc);
template<class T> void setUpdateCallback(const ref_ptr<T>& nc) { setUpdateCallback(nc.get()); }
/** Get update node callback, called during update traversal. */
inline Callback* getUpdateCallback() { return _updateCallback.get(); }
@@ -226,6 +228,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void addUpdateCallback(const ref_ptr<T>& nc) { addUpdateCallback(nc.get()); }
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeUpdateCallback(Callback* nc) {
if (nc != NULL && _updateCallback.valid()) {
@@ -239,6 +243,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void removeUpdateCallback(const ref_ptr<T>& nc) { removeUpdateCallback(nc.get()); }
/** Get the number of Children of this node which require Update traversal,
* since they have an Update Callback attached to them or their children.*/
inline unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; }
@@ -247,6 +253,8 @@ class OSG_EXPORT Node : public Object
/** Set event node callback, called during event traversal. */
void setEventCallback(Callback* nc);
template<class T> void setEventCallback(const ref_ptr<T>& nc) { setEventCallback(nc.get()); }
/** Get event node callback, called during event traversal. */
inline Callback* getEventCallback() { return _eventCallback.get(); }
@@ -261,6 +269,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void addEventCallback(const ref_ptr<T>& nc) { addEventCallback(nc.get()); }
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeEventCallback(Callback* nc) {
if (nc != NULL && _eventCallback.valid()) {
@@ -274,7 +284,9 @@ class OSG_EXPORT Node : public Object
}
}
/** Get the number of Children of this node which require Event traversal,
template<class T> void removeEventCallback(const ref_ptr<T>& nc) { removeEventCallback(nc.get()); }
/** Get the number of Children of this node which require Event traversal,
* since they have an Event Callback attached to them or their children.*/
inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; }
@@ -282,6 +294,8 @@ class OSG_EXPORT Node : public Object
/** Set cull node callback, called during cull traversal. */
void setCullCallback(Callback* nc) { _cullCallback = nc; }
template<class T> void setCullCallback(const ref_ptr<T>& nc) { setCullCallback(nc.get()); }
/** Get cull node callback, called during cull traversal. */
inline Callback* getCullCallback() { return _cullCallback.get(); }
@@ -296,6 +310,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void addCullCallback(const ref_ptr<T>& nc) { addCullCallback(nc.get()); }
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeCullCallback(Callback* nc) {
if (nc != NULL && _cullCallback.valid()) {
@@ -309,6 +325,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void removeCullCallback(const ref_ptr<T>& nc) { removeCullCallback(nc.get()); }
/** Set the view frustum/small feature culling of this node to be active or inactive.
* The default value is true for _cullingActive. Used as a guide
* to the cull traversal.*/
@@ -360,6 +378,8 @@ class OSG_EXPORT Node : public Object
/** Set the node's StateSet.*/
void setStateSet(osg::StateSet* stateset);
template<class T> void setStateSet(const osg::ref_ptr<T>& stateset) { setStateSet(stateset.get()); }
/** return the node's StateSet, if one does not already exist create it
* set the node and return the newly created StateSet. This ensures
* that a valid StateSet is always returned and can be used directly.*/
@@ -444,6 +464,8 @@ class OSG_EXPORT Node : public Object
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundingSphereCallback(ComputeBoundingSphereCallback* callback) { _computeBoundCallback = callback; }
template<class T> void setComputeBoundingSphereCallback(const ref_ptr<T>& callback) { setComputeBoundingSphereCallback(callback.get()); }
/** Get the compute bound callback.*/
ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() { return _computeBoundCallback.get(); }