Changeset 1181

Show
Ignore:
Timestamp:
04/20/08 10:27:32 (3 weeks ago)
Author:
vossg
Message:

fixed : dependend double deletes (ref + weak)

: visit subtree loop

changed: ptr cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Source/System/FieldContainer/Base/OSGFieldContainer.inl

    r1174 r1181  
    113113void FieldContainer::addReferenceUnrecordedX(void) 
    114114{ 
     115#ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
     116    FINFO(("FieldContainer::addReferenceUnrec [%p] [%d] [%s] START - [%d %d]\n", 
     117           this,  
     118           this->getId(),  
     119           this->getType().getCName(), 
     120           this->_iRefCount,  
     121           this->_iWeakRefCount)); 
     122#endif 
     123 
    115124    ++_iRefCount; 
     125 
     126#ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
     127    FINFO(("FieldContainer::addReferenceUnrec [%p] [%d] [%s] STOP - [%d %d]\n", 
     128           this,  
     129           this->getId(),  
     130           this->getType().getCName(), 
     131           this->_iRefCount,  
     132           this->_iWeakRefCount)); 
     133#endif 
    116134     
    117135//    Thread::getCurrentChangeList()->addAddRefd(Inherited::getId()); 
     
    129147#endif 
    130148 
    131     --_iRefCount; 
    132  
    133 #ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
    134     FINFO(("FieldContainer::subReference [%p] [%d] [%s] STOP - [%d %d]\n", 
    135            this,  
    136            this->getId(),  
    137            this->getType().getCName(), 
    138            this->_iRefCount,  
    139            this->_iWeakRefCount)); 
    140 #endif 
    141  
    142     if(_iRefCount <= 0 && _iWeakRefCount <= 0) 
     149    if(_iRefCount <= 1) 
    143150    { 
    144151        Thread::getCurrentChangeList()->incSubRefLevel(); 
     
    150157        Thread::getCurrentChangeList()->addSubRefd(Inherited::getId()); 
    151158 
    152 #ifdef OSG_MT_CPTR_ASPECT 
    153         this->onDestroyAspect(Inherited::getId(), Thread::getCurrentAspect()); 
    154  
    155         _pAspectStore->removePtrForAspect(Thread::getCurrentAspect()); 
    156  
    157         if(_pAspectStore->getRefCount() == 1) 
     159        if(_iWeakRefCount <= 0) 
    158160        { 
    159             this->deregister(Inherited::getId()); 
    160             this->onDestroy (Inherited::getId()); 
     161#ifdef OSG_MT_CPTR_ASPECT 
     162            this->onDestroyAspect(Inherited::getId(),  
     163                                  Thread::getCurrentAspect()); 
     164 
     165            _pAspectStore->removePtrForAspect(Thread::getCurrentAspect()); 
     166 
     167            if(_pAspectStore->getRefCount() == 1) 
     168            { 
     169                this->deregister(Inherited::getId()); 
     170                this->onDestroy (Inherited::getId()); 
     171            } 
     172 
     173            OSG::subRef(_pAspectStore); 
     174#else 
     175            this->deregister     (Inherited::getId()   ); 
     176            this->onDestroyAspect(Inherited::getId(), 0); 
     177            this->onDestroy      (Inherited::getId()   ); 
     178#endif 
     179             
     180            delete this; 
    161181        } 
    162  
    163         OSG::subRef(_pAspectStore); 
     182        else 
     183        { 
     184            --_iRefCount; 
     185 
     186#ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
     187            FINFO( 
     188                ("FieldContainer::subReference [%p] [%d] [%s] STOP A [%d %d]\n", 
     189                 this,  
     190                 this->getId(),  
     191                 this->getType().getCName(), 
     192                 this->_iRefCount,  
     193                 this->_iWeakRefCount)); 
     194#endif 
     195        } 
     196    } 
     197    else 
     198    { 
     199        --_iRefCount; 
     200 
     201#ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
     202        FINFO( 
     203            ("FieldContainer::subReference [%p] [%d] [%s] STOP B [%d %d]\n", 
     204             this,  
     205             this->getId(),  
     206             this->getType().getCName(), 
     207             this->_iRefCount,  
     208             this->_iWeakRefCount)); 
     209#endif 
     210 
     211        Thread::getCurrentChangeList()->addSubRefd(Inherited::getId()); 
     212    } 
     213 
     214
     215 
     216inline 
     217void FieldContainer::subReferenceUnrecordedX(void) 
     218
     219#ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
     220    FINFO(("FieldContainer::subReferenceUnrec [%p] [%d] [%s] START - [%d %d]\n", 
     221           this,  
     222           this->getId(),  
     223           this->getType().getCName(), 
     224           this->_iRefCount,  
     225           this->_iWeakRefCount)); 
     226#endif 
     227 
     228    if(_iRefCount <= 1) 
     229    { 
     230//      Thread::getCurrentChangeList()->incSubRefLevel(); 
     231 
     232        this->resolveLinks(); 
     233 
     234//        Thread::getCurrentChangeList()->decSubRefLevel(); 
     235 
     236//        Thread::getCurrentChangeList()->addSubRefd(Inherited::getId()); 
     237 
     238        if(_iWeakRefCount <= 0) 
     239        { 
     240#ifdef OSG_MT_CPTR_ASPECT 
     241            this->onDestroyAspect(Inherited::getId(),  
     242                                  Thread::getCurrentAspect()); 
     243 
     244            _pAspectStore->removePtrForAspect(Thread::getCurrentAspect()); 
     245             
     246            if(_pAspectStore->getRefCount() == 1) 
     247            { 
     248                this->deregister(Inherited::getId()); 
     249                this->onDestroy (Inherited::getId()); 
     250            } 
     251             
     252            OSG::subRef(_pAspectStore); 
    164253#else 
    165         this->deregister     (Inherited::getId()   ); 
    166         this->onDestroyAspect(Inherited::getId(), 0); 
    167         this->onDestroy      (Inherited::getId()   ); 
    168 #endif 
    169  
    170         delete this; 
     254            this->deregister     (Inherited::getId()   ); 
     255            this->onDestroyAspect(Inherited::getId(), 0); 
     256            this->onDestroy      (Inherited::getId()   ); 
     257#endif 
     258 
     259            delete this; 
     260        } 
     261        else 
     262        { 
     263            --_iRefCount; 
     264 
     265#ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
     266            FINFO( 
     267                ("FieldContainer::subReferenceUnrec [%p] [%d] [%s] " 
     268                 "STOP A [%d %d]\n", 
     269                 this,  
     270                 this->getId(),  
     271                 this->getType().getCName(), 
     272                 this->_iRefCount,  
     273                 this->_iWeakRefCount)); 
     274#endif 
     275        } 
    171276    } 
    172277    else 
    173278    { 
    174         Thread::getCurrentChangeList()->addSubRefd(Inherited::getId()); 
    175     } 
    176  
    177 
    178  
    179 inline 
    180 void FieldContainer::subReferenceUnrecordedX(void) 
    181 
    182 #ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
    183     FINFO(("FieldContainer::subReference [%p] [%d] [%s] START - [%d %d]\n", 
    184            this,  
    185            this->getId(),  
    186            this->getType().getCName(), 
    187            this->_iRefCount,  
    188            this->_iWeakRefCount)); 
    189 #endif 
    190  
    191     --_iRefCount; 
    192  
    193 #ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
    194     FINFO(("FieldContainer::subReference [%p] [%d] [%s] STOP - [%d %d]\n", 
    195            this,  
    196            this->getId(),  
    197            this->getType().getCName(), 
    198            this->_iRefCount,  
    199            this->_iWeakRefCount)); 
    200 #endif 
    201  
    202     if(_iRefCount <= 0 && _iWeakRefCount <= 0) 
    203     { 
    204 //      Thread::getCurrentChangeList()->incSubRefLevel(); 
    205  
    206         this->resolveLinks(); 
    207  
    208 //        Thread::getCurrentChangeList()->decSubRefLevel(); 
    209  
    210 //        Thread::getCurrentChangeList()->addSubRefd(Inherited::getId()); 
    211  
    212 #ifdef OSG_MT_CPTR_ASPECT 
    213         this->onDestroyAspect(Inherited::getId(), Thread::getCurrentAspect()); 
    214  
    215         _pAspectStore->removePtrForAspect(Thread::getCurrentAspect()); 
    216  
    217         if(_pAspectStore->getRefCount() == 1) 
    218         { 
    219             this->deregister(Inherited::getId()); 
    220             this->onDestroy (Inherited::getId()); 
    221         } 
    222  
    223         OSG::subRef(_pAspectStore); 
    224 #else 
    225         this->deregister     (Inherited::getId()   ); 
    226         this->onDestroyAspect(Inherited::getId(), 0); 
    227         this->onDestroy      (Inherited::getId()   ); 
    228 #endif 
    229  
    230         delete this; 
    231     } 
    232     else 
    233     { 
     279        --_iRefCount; 
     280 
     281#ifndef OSG_FIELDCONTAINER_DEBUG_SILENT 
     282        FINFO(("FieldContainer::subReferenceUnrec [%p] [%d] [%s] " 
     283               "STOP - [%d %d]\n", 
     284               this,  
     285               this->getId(),  
     286               this->getType().getCName(), 
     287               this->_iRefCount,  
     288               this->_iWeakRefCount)); 
     289#endif 
    234290//        Thread::getCurrentChangeList()->addSubRefd(Inherited::getId()); 
    235291    } 
  • trunk/Source/System/FieldContainer/Base/OSGRefCountPolicies.h

    r1177 r1181  
    8787    static void convertTransitPtr(T *&pOut, U *&pIn) 
    8888    { 
     89        RecordedRefCountPolicy::subRef(pOut); 
     90 
    8991        pOut = pIn; 
    9092        pIn  = NULL; 
     
    150152    static void convertTransitPtr(T *&pOut, U *&pIn) 
    151153    { 
     154        UnrecordedRefCountPolicy::subRef(pOut); 
     155 
    152156        pOut = pIn; 
    153157        pIn  = NULL; 
  • trunk/Source/System/FieldContainer/Base/OSGRefCountPtr.h

    r1177 r1181  
    181181template <class TargetObjectT, class SourceObjectT, class RP> inline 
    182182RefCountPtr<TargetObjectT, RP> dynamic_pointer_cast( 
    183     RefCountPtr<SourceObjectT, RP> const &source) 
    184 
    185     TargetObjectT *pRet = dynamic_cast<TargetObjectT *>(source.get()); 
    186  
    187     return RefCountPtr<TargetObjectT, RP>(pRet); 
    188 
     183    RefCountPtr<SourceObjectT, RP> const &source); 
     184  
     185template <class TargetObjectT, class SourceObjectT, class RP> inline 
     186RefCountPtr<TargetObjectT, RP> static_pointer_cast( 
     187    RefCountPtr<SourceObjectT, RP> const &source); 
    189188   
    190189OSG_END_NAMESPACE 
  • trunk/Source/System/FieldContainer/Base/OSGRefCountPtr.inl

    r1177 r1181  
    6969template <class OtherObjectT   > inline 
    7070RefCountPtr<ObjectT, RefCountPolicyT>::RefCountPtr( 
    71     TransitPtr<OtherObjectT> const &other) 
     71    TransitPtr<OtherObjectT> const &other) : 
     72 
     73    _pObj(NULL) 
    7274{ 
    7375    RefCountPolicy::convertTransitPtr(_pObj, other._pObj); 
     
    7880          class RefCountPolicyT> inline 
    7981RefCountPtr<ObjectT, RefCountPolicyT>::RefCountPtr( 
    80     ObjectTransitPtr const &other) 
     82    ObjectTransitPtr const &other) : 
     83 
     84    _pObj(NULL) 
    8185{ 
    8286    RefCountPolicy::convertTransitPtr(_pObj, other._pObj); 
     
    195199} 
    196200 
     201 
     202template <class TargetObjectT, class SourceObjectT, class RP> inline 
     203RefCountPtr<TargetObjectT, RP> dynamic_pointer_cast( 
     204    RefCountPtr<SourceObjectT, RP> const &source) 
     205{ 
     206    TargetObjectT *pRet = dynamic_cast<TargetObjectT *>(source.get()); 
     207 
     208    return RefCountPtr<TargetObjectT, RP>(pRet); 
     209} 
     210  
     211template <class TargetObjectT, class SourceObjectT, class RP> inline 
     212RefCountPtr<TargetObjectT, RP> static_pointer_cast( 
     213    RefCountPtr<SourceObjectT, RP> const &source) 
     214{ 
     215    TargetObjectT *pRet = static_cast<TargetObjectT *>(source.get()); 
     216 
     217    return RefCountPtr<TargetObjectT, RP>(pRet); 
     218} 
     219   
    197220OSG_END_NAMESPACE 
  • trunk/Source/System/FieldContainer/Base/OSGTransitPtr.h

    r1177 r1181  
    5959          class RefCountPolicyT> 
    6060class RefCountPtr; 
     61 
     62template <class TargetObjectT, class SourceObjectT> inline 
     63TransitPtr<TargetObjectT> dynamic_pointer_cast( 
     64    TransitPtr<SourceObjectT> const &source); 
     65 
     66template <class TargetObjectT, class SourceObjectT> inline 
     67TransitPtr<TargetObjectT> static_pointer_cast( 
     68    TransitPtr<SourceObjectT> const &source); 
    6169 
    6270template <class ObjectT> 
     
    144152#endif 
    145153 
     154    /*! \}                                                                 */ 
     155    /*=========================  PROTECTED  ===============================*/ 
     156 
     157  protected: 
     158 
     159    /*==========================  PRIVATE  ================================*/ 
     160 
     161    /*---------------------------------------------------------------------*/ 
     162    /*! \name Member                                                       */ 
     163    /*! \{                                                                 */ 
     164     
     165    mutable ObjectPtr _pObj; 
     166     
     167    /*! \}                                                                 */ 
     168    /*---------------------------------------------------------------------*/ 
     169    /*! \name Access                                                       */ 
     170    /*! \{                                                                 */ 
     171 
    146172    template<class SourceObjectT> 
    147     void dynamic_cast_set(TransitPtr<SourceObjectT> const &source) 
    148     { 
    149         ObjectPtr pObj = dynamic_cast<ObjectPtr>(source._pObj); 
    150  
    151         if(pObj != NULL) 
    152         { 
    153             _pObj = pObj; 
    154  
    155             source._pObj = NULL; 
    156         } 
    157     } 
    158  
    159     /*! \}                                                                 */ 
    160     /*=========================  PROTECTED  ===============================*/ 
    161  
    162   protected: 
    163  
    164     /*==========================  PRIVATE  ================================*/ 
    165  
    166     /*---------------------------------------------------------------------*/ 
    167     /*! \name Member                                                       */ 
    168     /*! \{                                                                 */ 
    169      
    170     mutable ObjectPtr _pObj; 
    171      
     173    void dynamic_cast_set(TransitPtr<SourceObjectT> const &source); 
     174 
     175    template<class SourceObjectT> 
     176    void static_cast_set (TransitPtr<SourceObjectT> const &source); 
     177 
    172178    /*! \}                                                                 */ 
    173179    /*---------------------------------------------------------------------*/ 
     
    178184    /*! \name Internal Helpers                                             */ 
    179185    /*! \{                                                                 */ 
     186 
     187    template <class TargetObjectT, class SourceObjectT>  
     188    friend TransitPtr<TargetObjectT> dynamic_pointer_cast( 
     189        TransitPtr<SourceObjectT> const &source); 
     190 
     191    template <class TargetObjectT, class SourceObjectT>  
     192    friend TransitPtr<TargetObjectT> static_pointer_cast( 
     193        TransitPtr<SourceObjectT> const &source); 
    180194 
    181195    /*! \}                                                                 */ 
  • trunk/Source/System/FieldContainer/Base/OSGTransitPtr.inl

    r1177 r1181  
    159159} 
    160160 
     161template<class ObjectT>  
     162template<class SourceObjectT> inline 
     163void TransitPtr<ObjectT>::dynamic_cast_set( 
     164    TransitPtr<SourceObjectT> const &source) 
     165{ 
     166    ObjectPtr pObj = dynamic_cast<ObjectPtr>(source._pObj); 
     167     
     168    if(pObj != NULL) 
     169    { 
     170        _pObj = pObj; 
     171         
     172        source._pObj = NULL; 
     173    } 
     174} 
     175 
     176template<class ObjectT>  
     177template<class SourceObjectT> inline 
     178void TransitPtr<ObjectT>::static_cast_set( 
     179    TransitPtr<SourceObjectT> const &source) 
     180{ 
     181    ObjectPtr pObj = static_cast<ObjectPtr>(source._pObj); 
     182     
     183    if(pObj != NULL) 
     184    { 
     185        _pObj = pObj; 
     186         
     187        source._pObj = NULL; 
     188    } 
     189} 
     190 
     191 
    161192OSG_END_NAMESPACE 
    162193 
  • trunk/Source/System/NodeCores/Groups/DynamicStateGenerators/testCubemapGenerator.cpp

    r1176 r1181  
    218218    { 
    219219        case 27:     
     220 
     221            fprintf(stderr, "Start Destruction\n\n"); 
     222 
    220223            delete rentravact; 
    221224 
     
    386389    GroupUnrecPtr b1  = Group::create(); 
    387390 
     391    fprintf(stderr, "Create b1n %p %d %d \n", 
     392            b1n.get(), 
     393            b1n->getRefCount(), 
     394            b1n->getWeakRefCount()); 
     395 
    388396    b1n->setCore( b1 ); 
    389397 
     
    394402    t1n->setCore (t1 ); 
    395403    t1n->addChild(b1n); 
     404 
     405    fprintf(stderr, "Create t1n %p %d %d \n", 
     406            t1n.get(), 
     407            t1n->getRefCount(), 
     408            t1n->getWeakRefCount()); 
    396409 
    397410    cam_trans = t1; 
     
    411424    } 
    412425 
     426    fprintf(stderr, "Create dlight %p %d %d \n", 
     427            dlight.get(), 
     428            dlight->getRefCount(), 
     429            dlight->getWeakRefCount()); 
    413430 
    414431    hdrroot = Node::create(); 
     
    424441    hdrroot->setCore (pHDR   ); 
    425442 
     443    fprintf(stderr, "Create hdrroot %p %d %d \n", 
     444            hdrroot.get(), 
     445            hdrroot->getRefCount(), 
     446            hdrroot->getWeakRefCount()); 
     447 
    426448    // root 
    427449    root         = Node:: create(); 
     
    436458    root->addChild(t1n   ); 
    437459    root->addChild(dlight); 
     460 
     461    fprintf(stderr, "Create root %p %d %d \n", 
     462            root.get(), 
     463            root->getRefCount(), 
     464            root->getWeakRefCount()); 
    438465 
    439466    // Load the file 
     
    581608    tball.setRotationCenter  (tCenter             ); 
    582609 
    583      
     610    fprintf(stderr, "Create b1n %p %d %d \n", 
     611            b1n.get(), 
     612            b1n->getRefCount(), 
     613            b1n->getWeakRefCount()); 
     614 
     615    fprintf(stderr, "Create t1n %p %d %d \n", 
     616            t1n.get(), 
     617            t1n->getRefCount(), 
     618            t1n->getWeakRefCount()); 
     619 
     620    fprintf(stderr, "Create dlight %p %d %d \n", 
     621            dlight.get(), 
     622            dlight->getRefCount(), 
     623            dlight->getWeakRefCount()); 
     624 
     625    fprintf(stderr, "Create hdrroot %p %d %d \n", 
     626            hdrroot.get(), 
     627            hdrroot->getRefCount(), 
     628            hdrroot->getWeakRefCount()); 
     629 
     630    fprintf(stderr, "Create root %p %d %d \n", 
     631            root.get(), 
     632            root->getRefCount(), 
     633            root->getWeakRefCount()); 
     634 
    584635    return 0; 
    585636} 
     
    588639{ 
    589640    doMain(argc, argv); 
     641 
     642    fprintf(stderr, "Create hdrroot %p %d %d \n", 
     643            hdrroot.get(), 
     644            hdrroot->getRefCount(), 
     645            hdrroot->getWeakRefCount()); 
     646 
     647    fprintf(stderr, "Create root %p %d %d \n", 
     648            root.get(), 
     649            root->getRefCount(), 
     650            root->getWeakRefCount()); 
    590651 
    591652    // run... 
  • trunk/Source/System/NodeCores/Groups/Misc/OSGVisitSubTree.fcd

    r435 r1181  
    1919        <Field 
    2020                name="subTreeRoot" 
    21                 type="NodePtr" 
     21                type="Node" 
     22                category="weakpointer" 
    2223                cardinality="single" 
    2324                visibility="external" 
  • trunk/Source/System/NodeCores/Groups/Misc/OSGVisitSubTreeBase.cpp

    r1101 r1181  
    9898 
    9999 
    100     pDesc = new SFUnrecNodePtr::Description( 
    101         SFUnrecNodePtr::getClassType(), 
     100    pDesc = new SFWeakNodePtr::Description( 
     101        SFWeakNodePtr::getClassType(), 
    102102        "subTreeRoot", 
    103103        "Reference to the sub-graph to draw in place of this node.\n" 
     
    145145    "        <Field\n" 
    146146    "                name=\"subTreeRoot\"\n" 
    147     "                type=\"NodePtr\"\n" 
     147    "                type=\"Node\"\n" 
     148    "                category=\"weakpointer\"\n" 
    148149    "                cardinality=\"single\"\n" 
    149150    "                visibility=\"external\"\n" 
     
    183184 
    184185//! Get the VisitSubTree::_sfSubTreeRoot field. 
    185 const SFUnrecNodePtr *VisitSubTreeBase::getSFSubTreeRoot(void) const 
     186const SFWeakNodePtr *VisitSubTreeBase::getSFSubTreeRoot(void) const 
    186187{ 
    187188    return &_sfSubTreeRoot; 
     
    349350GetFieldHandlePtr VisitSubTreeBase::getHandleSubTreeRoot     (void) const 
    350351{ 
    351     SFUnrecNodePtr::GetHandlePtr returnValue( 
    352         new  SFUnrecNodePtr::GetHandle( 
     352    SFWeakNodePtr::GetHandlePtr returnValue( 
     353        new  SFWeakNodePtr::GetHandle( 
    353354             &_sfSubTreeRoot,  
    354355             this->getType().getFieldDesc(SubTreeRootFieldId))); 
     
    359360EditFieldHandlePtr VisitSubTreeBase::editHandleSubTreeRoot    (void) 
    360361{ 
    361     SFUnrecNodePtr::EditHandlePtr returnValue( 
    362         new  SFUnrecNodePtr::EditHandle( 
     362    SFWeakNodePtr::EditHandlePtr returnValue( 
     363        new  SFWeakNodePtr::EditHandle( 
    363364             &_sfSubTreeRoot,  
    364365             this->getType().getFieldDesc(SubTreeRootFieldId))); 
  • trunk/Source/System/NodeCores/Groups/Misc/OSGVisitSubTreeBase.h

    r1178 r1181  
    126126    /*! \{                                                                 */ 
    127127 
    128             const SFUnrecNodePtr      *getSFSubTreeRoot     (void) const; 
     128            const SFWeakNodePtr       *getSFSubTreeRoot     (void) const; 
    129129 
    130130 
     
    196196    /*! \{                                                                 */ 
    197197 
    198     SFUnrecNodePtr    _sfSubTreeRoot; 
     198    SFWeakNodePtr     _sfSubTreeRoot; 
    199199 
    200200    /*! \}                                                                 */