BaseFile->Open crash



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

    On 12/02/2005 at 10:27, xxxxxxxx wrote:

    AutoAlloc<BaseFile> bfile;
    if (!bfile) /* panic */
    bfile->Open(...);
    // do file stuff
    bfile->Close();
    // bfile is automatically Free()'d when it goes out of scope

    or

    BaseFile *bfile;
    if (!(bfile = BaseFile::Alloc()) /* panic */
    bfile->Open(...);
    // do file stuff
    bfile->Close();
    BaseFile::Free(bfile);



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

    On 13/02/2005 at 08:48, xxxxxxxx wrote:

    thanks, it doesnt crash now,
    but my plugin still doesnt create a file ) :
    what´s wrong, this time

    LONG SMDFilter::Save(PluginSceneSaver *node, const Filename &name, BaseDocument *doc, LONG flags)
    {
     doc = GetActiveDocument();
        BaseObject *obj = doc->GetActiveObject();
        if(obj)
        {
      //IO
      AutoAlloc<BaseFile> bfile;
      if (!bfile) MessageDialog(" - no file");
      bfile->Open(name,GE_WRITE);
      bfile->WriteString("Claude Bonet Tags: ");
      bfile->Close();
    ...



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

    On 13/02/2005 at 09:20, xxxxxxxx wrote:

    Have you checked that 'name' has content and points to a valid path?

    I can't see anything obviously wrong, otherwise.



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

    On 13/02/2005 at 10:17, xxxxxxxx wrote:

    BaseFile *file;
      file = BaseFile::Alloc();
      file->Open(name,GE_WRITE);
      file->WriteString("test");
      BaseFile::Free(file);
    i tried it this way, too
    nothing happens, no file created
    i can´t see the mistake
    could you give me a very little example for a plugin that saves a string to a file, plz ??
    thanks



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

    On 13/02/2005 at 11:23, xxxxxxxx wrote:

    It works fine for me here:

    AutoAlloc<BaseFile> bf;  
         if (!bf->Open(presetdirectory,GE_WRITE,FILE_NODIALOG,GE_MOTOROLA)) return FALSE;
    


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

    On 13/02/2005 at 12:17, xxxxxxxx wrote:

    ok, here is my code, i hope the variable "name" in the save-method is used correctly:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <c4d.h>
    class SMDFilter : SceneSaverData
    {
        public:
      virtual LONG Save(PluginSceneSaver *node, const Filename &name, BaseDocument *doc, LONG filterflags);
      static NodeData *Alloc(void) { return gNew SMDFilter; }
    };

    LONG SMDFilter::Save(PluginSceneSaver *node,const Filename &name, BaseDocument *doc, LONG flags)
    {
     doc = GetActiveDocument();
        BaseObject *obj = doc->GetActiveObject();
        if(obj)
        {
      //IO
      AutoAlloc<BaseFile> bf;
      if (!bf->Open(name,GE_WRITE,FILE_NODIALOG,GE_MOTOROLA))
      return FALSE;

    //Polygoncount
      char polybuffer [33];
      GePrint("all Vertices: ");
      GePrint(itoa(static_cast<PolygonObject *>(obj)->GetPointCount(),polybuffer,10));
      //Claudebonet test
            BaseTag *tag = obj->GetFirstTag();
      
      char ibuffer [33];
      int i=0;
            while(tag->GetType() == Tclaudebonet)
            {
       GePrint(".............");
       VariableTag *gtag = (VariableTag * )tag; 
       int cnt = gtag->GetDataCount();
       Real *value = (Real * )gtag->GetDataAddress();
       //read relevant values
       i=0;
       for(int a=0; a<cnt; a++)
       {
        if(value[a]==1.0) i++;
       }
       GePrint(itoa(i,ibuffer,10));
       //go to the next tag
       tag = tag->GetNext();
            }  
        } 
        else MessageDialog(" - no object");
       
        return TRUE;
    }
    Bool RegisterSMD(void)
    {
      if(!RegisterSceneSaverPlugin(1111111,"SMDex",0, SMDFilter::Alloc, EXECUTION_RESULT_OK, 0, NULL)) return FALSE;
      return TRUE;
    }

    if so, what´s wrong here ?
    thanks a lot for your help!!!



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

    On 13/02/2005 at 12:23, xxxxxxxx wrote:

    The rest of the code shouldn´t have an effect on the save operation. The save code is correct, not sure why it doesn´t work for you. I assume it has something to do with the SceneSaver hook. (however I cannot really judge it, as I haven´t used this hook yet).

    Mikael probably knows what´s wrong here, so I suggest to wait for his support.

    Katachi



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

    On 15/02/2005 at 10:51, xxxxxxxx wrote:

    ok, thanks anyway,
    i hope Mikael can help me, soon



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

    On 28/02/2005 at 13:11, xxxxxxxx wrote:

    What return values do you get when not file is created?



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

    On 28/02/2005 at 17:01, xxxxxxxx wrote:

    i dont see any values in return
    AutoAlloc<BaseFile> bf;
      if (!bf->Open(name,GE_WRITE,FILE_NODIALOG,GE_MOTOROLA))
      MessageDialog(" - no -");
    "- no -" never appears :(



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

    On 09/03/2005 at 06:06, xxxxxxxx wrote:

    i made another solution:
    ----------------------------------------------------------------

    void writetofile(FILE *fi, String st)
    {
     char *buffer = bNew char[st.GetLength()+1];
     for(int n=0; n < st.GetLength(); n++)
     {
      buffer[n] = st[n];
     }
     fwrite(buffer,1,st.GetLength(),fi);
    }
    LONG SMDFilter::Save(PluginSceneSaver *node,const Filename &name, BaseDocument *doc, LONG flags)
    {
     doc = GetActiveDocument();
        BaseObject *obj = doc->GetActiveObject();
        if(obj)
        {
      CHAR header[80];
      ClearMem(header,sizeof(header));
      String str = name.GetString(),
          slash = "/";
      //SUFFIX check
      if(str.SubStr(str.GetLength()-4,4) != ".smd") str += ".smd";
       
      LONG count = str.GetCString(header,78,St7bit);
      char *ch = bNew char[count+1];
      //String to Char
      for(int a=0; a < count; a++)
      {
       if(str[a]=='\') ch[a] = slash[0];
       else
        ch[a] = str[a];
      }
      FILE *datei;
      datei = fopen(ch,"w+");
      if(datei)
      {
       //file stuff
       writetofile(datei,"version 1\n");
       writetofile(datei,"nodes\n");
      }
      fclose(datei);
    //... other code


Log in to reply