Show
Ignore:
Timestamp:
12/03/07 15:48:13 (1 year ago)
Author:
cneumann
Message:

fixed: compile errors

reference counting


It compiles on linux (when disabling the VRML Loader) and the first
ref counting tests seem to work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/Carsten_PtrWork2/Source/System/FieldContainer/Base/OSGFieldContainerTest.cpp

    r955 r1030  
    5252{ 
    5353    OSG::NodePtr np = OSG::Node::create(); 
    54     CHECK(np->getRefCount() == 0); 
    55     CHECK(np->getWeakRefCount() == 0); 
     54    CHECK(np->getRefCount()         == 0); 
     55    CHECK(np->getExternalRefCount() == 0); 
     56    CHECK(np->getWeakRefCount()     == 0); 
    5657 
    5758    OSG::UInt32 node_id = getContainerId(np); 
     
    6465    CHECK(r); 
    6566    CHECK(r.get() == np); 
    66     CHECK(np->getRefCount() == 1); 
     67    CHECK(np->getRefCount()         == 0); 
     68    CHECK(np->getExternalRefCount() == 1); 
     69    CHECK(np->getWeakRefCount()     == 0); 
    6770 
    6871    { 
    69     OSG::NodeRefPtr r2(np); 
    70     CHECK(r2); 
    71     CHECK(r2.get() == np); 
    72     CHECK(np->getRefCount() == 2); 
     72        OSG::NodeRefPtr r2(np); 
     73        CHECK(r2); 
     74        CHECK(r2.get() == np); 
     75        CHECK(np->getRefCount()         == 0); 
     76        CHECK(np->getExternalRefCount() == 2); 
     77        CHECK(np->getWeakRefCount()     == 0); 
    7378    } 
    7479} 
     
    140145TEST(checkMemoryCleanup) 
    141146{ 
    142    // Check to make sure the memory is cleaned up correctly with an FCPtr 
    143    OSG::NodeRefPtr  node(OSG::Node::create()); 
    144    OSG::UInt32   node_id   = OSG::getContainerId(node.get()); 
    145    OSG::Int32    ref_count = getRefCount(node.get()); 
    146    OSG::commitChanges(); 
    147    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) != OSGNullFC); 
    148  
    149    // Now release the ref and check that it was collected 
    150    node = OSGNullFC; 
    151    OSG::commitChanges(); 
    152    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) == OSGNullFC); 
     147    // Check to make sure the memory is cleaned up correctly with an FCPtr 
     148    OSG::NodeRefPtr  node(OSG::Node::create()); 
     149    OSG::UInt32   node_id   = OSG::getContainerId(node.get()); 
     150    OSG::Int32    ref_count = getRefCount(node.get()); 
     151    OSG::commitChanges(); 
     152    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) != OSGNullFC); 
     153     
     154    // Now release the ref and check that it was collected 
     155    node = OSGNullFC; 
     156    OSG::commitChanges(); 
     157    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) == OSGNullFC); 
    153158} 
    154159 
     
    158163TEST(testUncommittedChangesRegression) 
    159164{ 
    160    // The idea here is to try to force a subref/addref change using an old 
    161    // entry that would contain invalid data 
    162    OSG::NodeRefPtr outer_node(OSG::Node::create()); 
    163    OSG::NodeRefPtr outer_node2(OSG::Node::create()); 
    164    for(unsigned i=0;i<100;i++) 
    165    { 
    166       if ((i%5) == 0) 
    167       { outer_node = OSG::NodeRefPtr(OSG::Node::create()); } 
    168  
    169       OSG::NodeRefPtr temp_node = outer_node2; 
    170       OSG::NodeRefPtr temp_node2 = outer_node2; 
    171  
    172       OSG::commitChanges(); 
    173       OSG::Thread::getCurrentChangeList()->commitChangesAndClear(); 
    174    }    
     165    // The idea here is to try to force a subref/addref change using an old 
     166    // entry that would contain invalid data 
     167    OSG::NodeRefPtr outer_node (OSG::Node::create()); 
     168    OSG::NodeRefPtr outer_node2(OSG::Node::create()); 
     169     
     170    for(unsigned i = 0; i < 100; ++i) 
     171    { 
     172        if((i % 5) == 0) 
     173        {  
     174            outer_node = OSG::NodeRefPtr(OSG::Node::create()); 
     175        } 
     176     
     177        OSG::NodeRefPtr temp_node  = outer_node2; 
     178        OSG::NodeRefPtr temp_node2 = outer_node2; 
     179     
     180        OSG::commitChanges(); 
     181        OSG::Thread::getCurrentChangeList()->commitChangesAndClear(); 
     182    }    
    175183} 
    176184 
     
    180188TEST(checkMemWithCoredNodes) 
    181189{ 
    182    OSG::TransformNodePtr xnode; 
    183    xnode = OSG::TransformNodePtr::create(); 
    184  
    185    OSG::TransformNodePtr xnode2; 
    186    xnode2 = OSG::TransformNodePtr::create(); 
    187    xnode2 = xnode; 
    188    xnode  = OSG::NullFC;    
     190    OSG::TransformNodePtr xnode; 
     191    xnode = OSG::TransformNodePtr::create(); 
     192     
     193    OSG::TransformNodePtr xnode2; 
     194    xnode2 = OSG::TransformNodePtr::create(); 
     195    xnode2 = xnode; 
     196    xnode  = OSG::NullFC;    
    189197} 
    190198 
    191199TEST(checkDanglingFcPtr) 
    192200{ 
    193    // Check to make sure that dangling FCPtrs are detected. 
    194    OSG::NodePtr node(OSG::Node::create()); 
    195    OSG::NodePtr node_copy = node; 
    196    OSG::FieldContainer*  the_fc = node.getBaseCPtr(); 
    197    OSG::UInt32        kids = node->getNChildren(); 
    198  
    199    OSG::UInt32   node_id = OSG::getContainerId(node); 
    200    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) != OSGNullFC); 
    201    OSG::UInt8* base_ptr = node._storeP; 
    202    CHECK((base_ptr != NULL) && (base_ptr == node_copy._storeP)); 
    203  
    204    OSG::subRef(node); 
    205    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) == OSGNullFC); 
    206    //CHECK(NULL == node._storeP);       // Subref clears the main one by default 
    207    CHECK(base_ptr == node_copy._storeP);  // Still points to an invalid object 
    208  
    209    // Now try some things that should fail 
    210    //CHECK_ASSERT( node_copy.getBaseCPtr() ); 
    211    //CHECK_ASSERT( node_copy->getNChildren() ); 
    212    /*  If it works, these should assert 
    213    the_fc = node_copy.getBaseCPtr(); 
    214    kids   = node_copy->getNChildren(); 
    215    */ 
     201    // Check to make sure that dangling FCPtrs are detected. 
     202    OSG::NodePtr node(OSG::Node::create()); 
     203    OSG::NodePtr node_copy = node; 
     204    OSG::FieldContainer*  the_fc = node.getBaseCPtr(); 
     205    OSG::UInt32        kids = node->getNChildren(); 
     206     
     207    OSG::UInt32   node_id = OSG::getContainerId(node); 
     208    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) != OSGNullFC); 
     209    OSG::UInt8* base_ptr = node._storeP; 
     210    CHECK((base_ptr != NULL) && (base_ptr == node_copy._storeP)); 
     211     
     212    OSG::subRef(node); 
     213    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) == OSGNullFC); 
     214    //CHECK(NULL == node._storeP);       // Subref clears the main one by default 
     215    CHECK(base_ptr == node_copy._storeP);  // Still points to an invalid object 
     216     
     217    // Now try some things that should fail 
     218    //CHECK_ASSERT( node_copy.getBaseCPtr() ); 
     219    //CHECK_ASSERT( node_copy->getNChildren() ); 
     220    /*  If it works, these should assert 
     221    the_fc = node_copy.getBaseCPtr(); 
     222    kids   = node_copy->getNChildren(); 
     223    */ 
    216224} 
    217225 
    218226TEST(checkDanglingFcPtrFreelist) 
    219227{ 
    220    // Check to make sure that dangling FCPtrs are detected even when memory is allocated in the middle 
    221    OSG::NodePtr node(OSG::Node::create()); 
    222    OSG::NodePtr node_copy = node; 
    223    OSG::UInt32   node_id = OSG::getContainerId(node); 
    224    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) != OSGNullFC); 
    225  
    226    OSG::UInt8* base_ptr = node._storeP; 
    227    CHECK((base_ptr != NULL) && (base_ptr == node_copy._storeP)); 
    228  
    229    OSG::subRef(node); 
    230    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) == OSGNullFC); 
    231    CHECK(base_ptr == node_copy._storeP);  // Still points to an invalid object 
    232  
    233    // Allocate and deallocate some memory 
    234    for (unsigned i=0; i<1000;i++) 
    235    
    236       OSG::NodeRefPtr       n(OSG::Node::create()); 
    237    
    238  
    239    // Now try some things that should fail 
    240    /*  If it works, these should assert. 
    241    OSG::FieldContainer* the_fc = node_copy.getBaseCPtr(); 
    242    OSG::UInt32          kids   = node_copy->getNChildren(); 
    243    */    
     228    // Check to make sure that dangling FCPtrs are detected even when memory is allocated in the middle 
     229    OSG::NodePtr node(OSG::Node::create()); 
     230    OSG::NodePtr node_copy = node; 
     231    OSG::UInt32   node_id = OSG::getContainerId(node); 
     232    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) != OSGNullFC); 
     233     
     234    OSG::UInt8* base_ptr = node._storeP; 
     235    CHECK((base_ptr != NULL) && (base_ptr == node_copy._storeP)); 
     236     
     237    OSG::subRef(node); 
     238    CHECK(OSG::FieldContainerFactory::the()->getContainer(node_id) == OSGNullFC); 
     239    CHECK(base_ptr == node_copy._storeP);  // Still points to an invalid object 
     240     
     241    // Allocate and deallocate some memory 
     242    for (unsigned i=0; i<1000;i++) 
     243   
     244        OSG::NodeRefPtr       n(OSG::Node::create()); 
     245   
     246     
     247    // Now try some things that should fail 
     248    /*  If it works, these should assert. 
     249    OSG::FieldContainer* the_fc = node_copy.getBaseCPtr(); 
     250    OSG::UInt32          kids   = node_copy->getNChildren(); 
     251    */    
    244252} 
    245253