diff --git a/include/RefObject.h b/include/RefObject.h index 8720805b7d53b200a3ab33a9bc4471edc8b87598..3fc0772cacde7e3f54028b38168ae8a148290529 100644 --- a/include/RefObject.h +++ b/include/RefObject.h @@ -110,7 +110,7 @@ public: /*! NIFLIB_HIDDEN function. For internal use only. */ NIFLIB_HIDDEN virtual void Read( istream& in, list<unsigned int> & link_stack, const NifInfo & info ) = 0; /*! NIFLIB_HIDDEN function. For internal use only. */ - NIFLIB_HIDDEN virtual void Write( ostream& out, const map< Ref<NiObject>, unsigned int> & link_map, const NifInfo & info ) const = 0; + NIFLIB_HIDDEN virtual void Write( ostream& out, const map< Ref<NiObject>, unsigned int> & link_map, list<NiObject *> & missing_link_stack, const NifInfo & info ) const = 0; /*! NIFLIB_HIDDEN function. For internal use only. */ NIFLIB_HIDDEN virtual void FixLinks( const map<unsigned int, Ref<NiObject> > & objects, list<unsigned int> & link_stack, const NifInfo & info ) = 0; /*! NIFLIB_HIDDEN function. For internal use only. */ diff --git a/src/niflib.cpp b/src/niflib.cpp index 3521e2eee8b1a8919fdff749b94a989621adb358..60231eed38ed7afd392eabe1d4bff75c213ccffa 100644 --- a/src/niflib.cpp +++ b/src/niflib.cpp @@ -398,7 +398,9 @@ vector<NiObjectRef> ReadNifList( istream & in, NifInfo * info ) { } // Writes a valid Nif File given an ostream, a list to the root objects of a file tree -void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo & info ) { +// (missing_link_stack stores a stack of links which are referred to but which +// are not inside the tree rooted by roots) +void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, list<NiObject *> & missing_link_stack, const NifInfo & info) { //Enumerate all objects in tree map<Type*,unsigned int> type_map; @@ -463,7 +465,7 @@ void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo header.blockSize.resize( objects.size() ); for ( unsigned int i = 0; i < objects.size(); ++i ) { ostr.reset(); - objects[i]->Write( ostr, link_map, info ); + objects[i]->Write( ostr, link_map, missing_link_stack, info ); header.blockSize[i] = ostr.tellp(); } header.numStrings = header.strings.size(); @@ -505,7 +507,7 @@ void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo WriteUInt( 0, out ); } - objects[i]->Write( out, link_map, info ); + objects[i]->Write( out, link_map, missing_link_stack, info ); } //--Write Footer--// @@ -534,13 +536,18 @@ void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo footer.numRoots = roots.size(); footer.roots.insert(footer.roots.end(), roots.begin(), roots.end()); } - footer.Write( out, link_map, info ); + footer.Write( out, link_map, missing_link_stack, info ); } // clear the header pointer in the stream. Should be in try/catch block out << hdrInfo(NULL); } +void WriteNifTree( ostream & out, list<NiObjectRef> const & roots, const NifInfo & info) { + list<NiObject *> missing_link_stack; + WriteNifTree( out, roots, missing_link_stack, info ); +} + // Writes a valid Nif File given a file name, a pointer to the root object of a file tree void WriteNifTree( string const & file_name, NiObject * root, const NifInfo & info ) { //Open output file diff --git a/src/obj/NiObject.cpp b/src/obj/NiObject.cpp index 882ce9a864f81d39334ab0ee9ce218435cadc9e5..29a8ba9a18e96321dc01c5761759045536e48766 100644 --- a/src/obj/NiObject.cpp +++ b/src/obj/NiObject.cpp @@ -108,7 +108,8 @@ NiObjectRef NiObject::Clone( unsigned int version, unsigned int user_version ) { //Write this object's data to the stream NifInfo info( version, user_version ); - this->Write( tmp, link_map, info ); + list<NiObject *> missing_link_stack; + this->Write( tmp, link_map, missing_link_stack, info ); //Dummy stack list<unsigned int> link_stack;