Skip to content
Snippets Groups Projects
Commit 41a60f1e authored by Tazpn's avatar Tazpn
Browse files

Fix reference counting in base objects and crash in NiNode for some Nif files.

parent ee543a83
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,12 @@ protected:
};
template <class T>
Ref<T>::Ref( T * object ) : _object(object) {}
Ref<T>::Ref( T * object ) : _object(object) {
//If object isn't null, increment reference count
if ( _object != NULL ) {
_object->AddRef();
}
}
template <class T>
Ref<T>::Ref(const Ref & ref_to_copy ) {
......
......@@ -70,7 +70,7 @@ void NiNode::RemoveChild( Ref<NiAVObject> obj ) {
void NiNode::ClearChildren() {
for ( vector< NiAVObjectRef >::iterator it = children.begin(); it != children.end(); ++it) {
(*it)->SetParent(NULL);
if (*it) (*it)->SetParent(NULL);
}
children.clear();
}
......
......@@ -33,9 +33,7 @@ void NiObject::AddRef() {
}
void NiObject::SubtractRef() {
--_ref_count;
if ( _ref_count < 0 ) {
if ( --_ref_count == 0 ) {
delete this;
}
}
......
......@@ -151,7 +151,7 @@ template <class T> Ref<T> StaticCast( NiObject * object ) {
return (T*)object;
}
template <class T> const Ref<T> SaticCast (const NiObject * object) {
template <class T> Ref<const T> StaticCast (const NiObject * object) {
return (const T*)object;
}
......@@ -163,7 +163,7 @@ template <class T> Ref<T> DynamicCast( NiObject * object ) {
}
}
template <class T> const Ref<T> DynamicCast( const NiObject * object ) {
template <class T> Ref<const T> DynamicCast( const NiObject * object ) {
if ( object->IsDerivedType(T::TYPE) ) {
return (const T*)object;
} else {
......
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