2 Replies Latest reply on Oct 26, 2014 3:50 AM by Joydeep Ray

    Opening document in FileFormat plug-in crashes Illustrator

    Joydeep Ray

      Hi,

      I am trying to open an EPS file in the GoFileFormat() handler of a File Format plug-in, by the following code.

       

      AIDocumentListSuite* sAIDocumentList = nil;

      AIDocumentHandle document;

       

      message->d.basic->AcquireSuite(kAIDocumentListSuite, kAIDocumentListVersion, (const void **)&sAIDocumentList);

      error = sAIDocumentList->Open(ai::FilePath(ai::UnicodeString("D:\\MyFile.eps")), kAIUnknownColorModel, kDialogOff, false, &document);

      message->d.basic->ReleaseSuite(kAIDocumentListSuite, kAIDocumentListVersion);

       

       

      The file is getting opened and shown properly but as soon as the handler returns, Illustrator is crashing. In fact, Illustrator will crash if these lines are put in the GoFileFormat() handler of the TextFileFormat sample application also. However, I tried to put these same statements at some other place (e.g. against the click of a menu item), where they seem to be working properly. But it may be accidental also. What can be the reason? Is there some problem with this code? Or opening files this way is not possible in the GoFileFormat() handler, may be because it is already trying to open a new type of file? If that is the case, how should the code be modified? I need to open this eps file, actually more than one eps file, when the user chooses to open my special file type (Actually, the eps file names are mentioned in that file). I also tried to define the sAIDocumentList as a global pointer (like many other suite pointers in the samples), but the result remained same.

       

      Any help will be most appreciated.

       

      Thanks in advance,

      Joydeep Ray

        • 1. Re: Opening document in FileFormat plug-in crashes Illustrator
          LeoTaro Level 4

          Hello

           

          > Or opening files this way is not possible in the GoFileFormat() handler, may be because it is already trying to open a new type of file?

           

          I think this is probably the reason it is crashing.

           

          > If that is the case, how should the code be modified?


          You could use a timer. In your GoFileFormat() handler store the filename and then create a timer with a zero timeout.


               // Store filename etc

               sAITimer->AddTimer(message->d.self,"DocOpen",0,&docOpenTimer);

               return kBadParameterErr;


          In your GoTimer() handler, open the file and remove the timer:


           

              if (message->timer == docOpenTimer)

              {

                  sAITimer->SetTimerActive(message->timer,false);

                  // Open document code

              }


          • 2. Re: Opening document in FileFormat plug-in crashes Illustrator
            Joydeep Ray Level 1

            Hi Leo,

             

            Thanks for the pointer. For the time being I have bypassed the problem by subscribing to the notification kAIDocumentOpenedNotifier, which is fired after a document is opened. Once my .abc type of file is opened in Illustrator, when a blank document is shown, this handler is called. There I am checking if the currently opened document's filename is with extension ."abc" or not, and if so, I am opening all the EPS files and doing the processing, Files are opened correctly from there. Your solution looks much more elegant and I will try this approach later, but am in desperate hurry now with lot of new problems .

             

            Many thanks,

            Joydeep