Hello Michael,

On 05/08/2014 11:47 AM, Michael Raab wrote:
dynamic_pointer_cast<Viewport>(OSG::deepClone(*vit, cloneShareTypes));
The result was a StackOverflow Exception. I tried to debug the problem
and it seems deepClone tries to clone the window the viewport is
attached to.
I thought the share types definition should prevent deepClone from doing so.

yes, it appears this was only implemented for deepCloneTree (see Source/Base/FieldContainer/Base/Node/OSGNode.h). I'm attaching a patch that should fix it, would you mind giving it a try? Thanks!

        Cheers,
                Carsten
diff --git a/Source/Base/FieldContainer/Base/OSGFieldContainer.cpp b/Source/Base/FieldContainer/Base/OSGFieldContainer.cpp
index 84d658e..d3ef93e 100644
--- a/Source/Base/FieldContainer/Base/OSGFieldContainer.cpp
+++ b/Source/Base/FieldContainer/Base/OSGFieldContainer.cpp
@@ -844,7 +844,7 @@ FieldContainerTransitPtr deepClone(
         GetFieldHandlePtr  srcField = src    ->getField (i);
         EditFieldHandlePtr dstField = fcClone->editField(i);
 
-        if(dstField == NULL || dstField->isValid() == false || 
+        if(dstField == NULL || dstField->isValid() == false ||
            srcField == NULL || srcField->isValid() == false)
         {
             continue;
@@ -856,11 +856,60 @@ FieldContainerTransitPtr deepClone(
         }
         else
         {
-            dstField->cloneValues(srcField, 
-                                  shareTypes,    
-                                  ignoreTypes,
-                                  shareGroupIds, 
-                                  ignoreGroupIds);
+            // get type info for values stored in field
+            const DataType &contentType = srcField->getType().getContentType();
+
+            // check if it's a "pointer to FC" type (needed, because
+            // AttachmentMap also passes the above isPointerType() check)
+            const PointerType *pointerType =
+                dynamic_cast<const PointerType *>(&contentType);
+
+            // punt, share if it is something that is not "pointer to FC"
+            if(pointerType == NULL)
+            {
+                dstField->shareValues(srcField);
+                continue;
+            }
+
+            // get type info for pointed-to FC type
+            const ReflexiveContainerType *rcType =
+                dynamic_cast<const ReflexiveContainerType *>(
+                    &pointerType->getContentType());
+
+            // punt, share if it is something that is not derived from RC
+            if(rcType == NULL)
+            {
+                dstField->shareValues(srcField);
+                continue;
+            }
+
+            // check if type should be ignored
+            if(!TypePredicates::typeInGroupIds(
+                    ignoreGroupIds.begin(),
+                    ignoreGroupIds.end  (), *rcType) &&
+               !TypePredicates::typeDerivedFrom(
+                    ignoreTypes.begin(),
+                    ignoreTypes.end  (), *rcType)      )
+            {
+                // check if type should by shared
+                if(TypePredicates::typeInGroupIds(
+                        shareGroupIds.begin(),
+                        shareGroupIds.end  (), *rcType) &&
+                   TypePredicates::typeDerivedFrom(
+                        shareTypes.begin(),
+                        shareTypes.end  (), *rcType)      )
+                {
+                    dstField->shareValues(srcField);
+                }
+                else
+                {
+                    dstField->cloneValues(srcField,
+                                          shareTypes,
+                                          ignoreTypes,
+                                          shareGroupIds,
+                                          ignoreGroupIds);
+                }
+            }
         }
     }
 
------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to