Hello Michael,

Michael Raab wrote:
I finally got the backtrace, it is attached to this mail.

thanks!

Among other things, RemoteAspect::receiveSync is called. In this function I 
found the following comment:

// subref until the factory hat no // knowlage of the node
// we can do this here because in sendSync the destroys are coming
// after the changes, that's important because if
// rebuildState would be called
// after the StateChunk has been destroyed this would lead to some
// problems because the StateChunk is also referenced
// in the state and in the next rebuildState of the material
// the old already invalid chunk ptr is destroyed again!

May this has something to do with this crash?

yes, to some extent at least. The comment mainly explains why it is safe to handle a "destroy" change list entry by simply decrementing the ref count of an object until it is destroyed - it is safe because "changed" change list entries (that could potentially refer to the destroyed object) will already be handled at this point (they are sent before "destroyed" entries). The Material/State/StateChunk case is just mentioned as a concrete example where this is important (and probably it was discovered that way originally).

I have a couple of questions, that hopefully will allow us to narrow down on the real problem:

- do you have a reliable way to reproduce the crash? What is the sequence of things that lead to it? You mentioned that you are creating/destroying materials, but what has to happen to trigger the bug? I've tried to just change materials in testClusterClient, but that alone was not sufficient, so I suspect there is something else that has to happen.

- are you able to reproduce the problem with testClusterClient, probably after making some hackish modification to it (to keep it simple perhaps just make an explicit render() call from main, make a change, call render(), more changes if necessary, etc.) ?

- how do you ensure your materials are correctly ref counted? Do you store them in the application with RefPtr<MaterialPtr> (i.e. MaterialRefPtr) or as plain MaterialPtr? Do you manually do addRefCP/subRefCP calls? Does the problem perhaps only trigger if you add a material to an object, remove it and then add it again?

- can you give the attached patch a try? It fixes some missing begin/endEditCP calls in ChunkMaterial and State.

        Cheers,
                Carsten
Index: Source/System/Material/OSGChunkMaterial.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/Material/OSGChunkMaterial.cpp,v
retrieving revision 1.18
diff -u -p -r1.18 OSGChunkMaterial.cpp
--- Source/System/Material/OSGChunkMaterial.cpp	9 Jun 2008 07:30:40 -0000	1.18
+++ Source/System/Material/OSGChunkMaterial.cpp	22 Apr 2010 15:40:12 -0000
@@ -108,7 +108,11 @@ ChunkMaterial::ChunkMaterial(const Chunk
 
 ChunkMaterial::~ChunkMaterial(void)
 {
+    ChunkMaterialPtr thisPtr(this);
+
+    beginEditCP(thisPtr, ChunksFieldMask);
     clearChunks();
+    endEditCP(thisPtr, ChunksFieldMask);
 }
 
 void ChunkMaterial::changed(BitVector whichField, UInt32 origin)
Index: Source/System/State/OSGState.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/State/OSGState.cpp,v
retrieving revision 1.14
diff -u -p -r1.14 OSGState.cpp
--- Source/System/State/OSGState.cpp	18 Mar 2009 14:14:08 -0000	1.14
+++ Source/System/State/OSGState.cpp	22 Apr 2010 15:40:12 -0000
@@ -51,31 +51,6 @@
 
 #include "OSGState.h"
 
-
-#if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
-
-OSG_BEGIN_NAMESPACE
-
-/*! \ingroup STLHelpers
-    \hideinhierarchy
-    Helper struct to remove chunks from a state.
-*/
-
-struct ClearSlot : public std::unary_function<      StateChunkPtr         &, 
-                                              const NullFieldContainerPtr &>
-{
-    const NullFieldContainerPtr &operator() (StateChunkPtr &slotPtr) 
-    { 
-        subRefCP(slotPtr);
-        
-        return NullFC;
-    }
-};
-
-OSG_END_NAMESPACE
-
-#endif
-
 OSG_USING_NAMESPACE
 
 
@@ -132,7 +107,11 @@ State::State(const State &source) :
 
 State::~State(void)
 {
+    StatePtr thisPtr(this);
+
+    beginEditCP(thisPtr, ChunksFieldMask);
     clearChunks();
+    endEditCP(thisPtr, ChunksFieldMask);
 }
 
 #if defined(OSG_FIXED_MFIELDSYNC)
@@ -294,6 +273,8 @@ void State::deactivate(DrawActionBase *a
 
 bool State::addChunk(StateChunkPtr chunk, Int32 index)
 {
+    OSG_ASSERT(chunk != NullFC);
+
     if(index > 0 && index > chunk->getClass()->getNumSlots())
     {
         SWARNING << "addChunk: index " 
@@ -437,10 +418,15 @@ bool State::subChunk(UInt32 classid, Int
 
 void State::clearChunks(void)
 {
-    std::transform(_mfChunks.begin(), 
-                   _mfChunks.end  (), 
-                   _mfChunks.begin(),
-                    ClearSlot());
+    MFStateChunkPtr::iterator chunksIt  = _mfChunks.begin();
+    MFStateChunkPtr::iterator chunksEnd = _mfChunks.end  ();
+
+    for(; chunksIt != chunksEnd; ++chunksIt)
+    {
+        subRefCP(*chunksIt);
+
+        *chunksIt = NullFC;
+    }
 }
 
 /*-------------------------- comparison -----------------------------------*/
------------------------------------------------------------------------------
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to