| 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); |
|---|
| 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 | } |
|---|
| 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 | */ |
|---|
| 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 | */ |
|---|