[CC'ing core list, hoping for some history ;) ]
Hello Marc,
Marc Hofmann wrote:
I have a problem with reference counting when using threads. Either my
program crashes or leaks memory.
thanks for sending the test program, very helpful!
3 situations (see code below in create(...)):
(1) Everything works like expected, node and geometry are deleted
correctly, no problem here.
(2) Similar to (1), but I add a property to the geometry, but the
program crashes during the last printOSGInstances() call
error message: access violation in
DynamicLoad.exe!osg::AttachmentContainerPtr::dcast<osg::FieldContainerPtr>(osg::FieldContainerPtr
oIn={...}) Zeile 56 + 0x4e Bytes
I think you found a pretty embarrassing bug in the Geometry...
It only removes itself as a parent of its GeoProperties (and decrements
their refcount) in onDestroy [1] which is called if the object goes away
across all aspects, while we want this to happen when the current aspect
copy goes away, i.e. in the d'tor -- at least if I recall the 1.x
details correctly, it's been a while ;)
Anyway, so the Geometry goes away, but its Properties (derived from
Attachment) still have pointers to it, so it crashes in your print function.
(3) Assume the printOSGInstances() function is wrong, I tried
utilize the task manager to see if there are any memory leaks, and the
memory usage grows steady up and never get freed.
yes, the properties keep lying around and never go away... ;-/
Can you try the attached patch, please?
Cheers,
Carsten
[1] the commit message that introduced the change reads:
"moved destructor code into onDestroy this fixed some strange gl object
create/destroy cycle (with the same id)"
I think the only part of the d'tor code that belongs into onDestroy is
the Window::destroyGLObject(getGLId()) call. Does anybody recall more
details about this?
Index: Source/System/NodeCores/Drawables/Geometry/OSGGeometry.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/NodeCores/Drawables/Geometry/OSGGeometry.cpp,v
retrieving revision 1.56
diff -u -r1.56 OSGGeometry.cpp
--- Source/System/NodeCores/Drawables/Geometry/OSGGeometry.cpp 28 Jan 2009 03:06:14 -0000 1.56
+++ Source/System/NodeCores/Drawables/Geometry/OSGGeometry.cpp 5 Jun 2009 22:08:15 -0000
@@ -212,39 +212,6 @@
*/
Geometry::~Geometry(void)
{
-}
-
-void Geometry::onCreate(const Geometry *)
-{
- // if we're in startup this is the prototype, which shouldn't have an id
- if(GlobalSystemState == Startup)
- return;
-
- // !!! this temporary is needed to work around compiler problems(sgi)
- // CHECK CHECK
-
- // TextureChunkPtr tmpPtr = FieldContainer::getPtr<TextureChunkPtr>(*this);
- if(Thread::getAspect() != _sfIgnoreGLForAspect.getValue())
- {
- GeometryPtr tmpPtr(*this);
-
- beginEditCP(tmpPtr, Geometry::GLIdFieldMask);
-
- setGLId(
- Window::registerGLObject(
- osgTypedMethodVoidFunctor2ObjCPtrPtr<GeometryPtr,
- Window ,
- UInt32>(tmpPtr,
- &Geometry::handleGL),
- 2));
-
- endEditCP(tmpPtr, Geometry::GLIdFieldMask);
- }
-}
-
-void Geometry::onDestroy(void)
-{
- Inherited::onDestroy();
GeometryPtr thisP = getPtr();
@@ -416,6 +383,39 @@
}
subRefCP(_sfMaterial.getValue());
+}
+
+void Geometry::onCreate(const Geometry *)
+{
+ // if we're in startup this is the prototype, which shouldn't have an id
+ if(GlobalSystemState == Startup)
+ return;
+
+ // !!! this temporary is needed to work around compiler problems(sgi)
+ // CHECK CHECK
+
+ // TextureChunkPtr tmpPtr = FieldContainer::getPtr<TextureChunkPtr>(*this);
+ if(Thread::getAspect() != _sfIgnoreGLForAspect.getValue())
+ {
+ GeometryPtr tmpPtr(*this);
+
+ beginEditCP(tmpPtr, Geometry::GLIdFieldMask);
+
+ setGLId(
+ Window::registerGLObject(
+ osgTypedMethodVoidFunctor2ObjCPtrPtr<GeometryPtr,
+ Window ,
+ UInt32>(tmpPtr,
+ &Geometry::handleGL),
+ 2));
+
+ endEditCP(tmpPtr, Geometry::GLIdFieldMask);
+ }
+}
+
+void Geometry::onDestroy(void)
+{
+ Inherited::onDestroy();
if(getGLId() > 0)
{
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Opensg-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-core