Freeing Loaded BaseDocument

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/08/2003 at 18:25, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   8.100 
Platform:      Mac OSX  ; 
Language(s) :     C++  ;

---------
I'm writing a file-animation plugin (ie one which loads a different file per frame), and everything works fine until I try to free the document I've loaded.

I've tried using BaseDocument::Free() and also ::KillDocument(), but both crash C4D.

Here's the relevant bit of code:

  
class FileAnim : public ObjectData  
{  
// ...                                                                         
BaseDocument* _anidoc; // initted to 0 in FileAnim()                            
};  
  
BaseObject*  
FileAnim::GetVirtualObjects(PluginObject* op, HierarchyHelp* hh)  
{  
Filename filenm;  
// ...                                                                         
// cache not valid: must load new file                                          
if (_anidoc)  
    {  
      // HELP! both of these will crash us!                                      
      ::KillDocument(_anidoc);  
      BaseDocument::Free(_anidoc);  
    }  
_anidoc = ::LoadDocument(filenm, true /*showerrors*/);  
return _anidoc->GetFirstObject();  
}  

How should I be freeing the loaded document?

Thanks.

.angus.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 28/08/2003 at 00:46, xxxxxxxx wrote:

You should remove the objects from the document before passing them from GetVirtualObjects(), then from your document. Only the first object and all children will be passed out using that method btw.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 28/08/2003 at 18:23, xxxxxxxx wrote:

Thanks David.
Now looks something like the following and works a treat.

  
// ...                                                                         
// cache invalid                                                                
BaseDocument* anidoc = ::LoadDocument(filenm, true /*showerrors*/);  
BaseObject* aniroot = BaseObject::Alloc(Onull);  
BaseObject* obj = anidoc->GetFirstObject();  
for ( ; obj; obj = obj->GetNext())  
    {  
      obj->Remove();    // remove from anidoc                                     
      obj->InsertUnderLast(aniroot);  
    }  
BaseDocument::Free(anidoc);  
return aniroot;  

.angus.