Skip to content
Snippets Groups Projects
Commit 5a05c615 authored by Shon Ferguson's avatar Shon Ferguson
Browse files

Fixed object auto-destruct, but introduced a strange phantom error.

parent d4825132
No related branches found
No related tags found
No related merge requests found
......@@ -108,7 +108,7 @@ public:
* Formats a human readable string that includes the type of the object
* \return A string in the form: address(type)
*/
NIFLIB_API virtual string GetIDString();
NIFLIB_API virtual string GetIDString() const;
/*!
* Used to retrieve all blocks that the current block is linked to through <i>all</i> attributes.
......
......@@ -2,7 +2,7 @@
All rights reserved. Please see niflib.h for licence. */
//#define DEBUG // this will produce lots of output
//#define PRINT_OBJECT_NAMES
#define PRINT_OBJECT_NAMES
//#define PRINT_OBJECT_CONTENTS
//#define DEBUG_LINK_PHASE
//#define DEBUG_HEADER_FOOTER
......
......@@ -87,7 +87,9 @@ void NiNode::RemoveChild( Ref<NiAVObject> obj ) {
void NiNode::ClearChildren() {
for ( vector< NiAVObjectRef >::iterator it = children.begin(); it != children.end(); ++it) {
if (*it) (*it)->SetParent(NULL);
if ( *it != NULL ) {
(*it)->SetParent(NULL);
}
}
children.clear();
}
......@@ -138,17 +140,12 @@ void NiNode::AddSkin( NiSkinInstance * skin_inst ) {
}
void NiNode::RemoveSkin( NiSkinInstance * skin_inst ) {
//Unflag any bones that were part of this skin instance
vector<NiNodeRef> bones = skin_inst->GetBones();
for ( uint i = 0; i < bones.size(); ++i ) {
bones[i]->SetSkinFlag(false);
}
//Remove the reference
skins.remove( skin_inst);
//Ensure that any multiply referenced bone nodes still
//have their skin flag set
vector<NiNodeRef> bones;
for ( list<NiSkinInstance*>::iterator it = skins.begin(); it != skins.end(); ++it ) {
bones = (*it)->GetBones();
for ( uint i = 0; i < bones.size(); ++i ) {
......
......@@ -11,8 +11,12 @@ const Type NiObject::TYPE("NiObject", NULL );
//Static to track total number of objects in memory. Initialize to zero.
unsigned int NiObject::objectsInMemory = 0;
NiObject::NiObject() : _ref_count(0) {}
NiObject::~NiObject() {}
NiObject::NiObject() : _ref_count(0) {
objectsInMemory++;
}
NiObject::~NiObject() {
objectsInMemory--;
}
bool NiObject::IsSameType( const Type & compare_to) const {
return GetType().IsSameType( compare_to );
......@@ -35,7 +39,9 @@ void NiObject::AddRef() const {
}
void NiObject::SubtractRef() const {
if ( _ref_count-- == 0 ) {
_ref_count--;
if ( _ref_count < 1 ) {
//cout << this->GetIDString() << " died." << endl;
delete this;
}
}
......@@ -59,7 +65,7 @@ list<NiObjectRef> NiObject::GetRefs() const {
}
/*! Used to format a human readable string that includes the type of the object */
string NiObject::GetIDString() {
string NiObject::GetIDString() const {
stringstream out;
out << this << "(" << this->GetType().GetTypeName() << ")";
return out.str();
......
......@@ -47,8 +47,18 @@ NiSkinInstance::NiSkinInstance( Ref<NiNode> skeleton_root, vector< Ref<NiNode> >
}
NiSkinInstance::~NiSkinInstance() {
//Probably not necessary, and not very safe
////Unflag any bones that were part of this skin instance
//for ( uint i = 0; i < bones.size(); ++i ) {
// cout << "Bone " << i << ":";
// cout << bones[i]->GetIDString() << endl;
// bones[i]->SetSkinFlag(false);
//}
//Inform Skeleton Root of detatchment and clear it.
skeletonRoot->RemoveSkin( this );
if ( skeletonRoot != NULL ) {
skeletonRoot->RemoveSkin( this );
}
}
void NiSkinInstance::Read( istream& in, list<uint> & link_stack, unsigned int version, unsigned int user_version ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment