0 Replies Latest reply on Jul 5, 2016 6:45 AM by lujun xi

    Why InDesign CC2015 crash when execute CmdUtils::ProcessCommand()

    lujun xi

      Hi, Everyone!


      I needs some help! Please!


      Now I want to replace the picture in RunThread() method. But InDesign CC2015 is crashed when execute CmdUtils::ProcessCommand() which is inside RunThread() method. Outside of the RunThread() method, it is OK. And the same code executed on InDesign CC 2014.0 is OK, but crashed on InDesign CC 2014.2.


      Does anyone knows why?  Please give me some advice. Thank you very mach.


      This is my code:

      // Action
      void MWDUActionComponent::DoAction(IActiveContext* ac, ActionID actionID, GSysPoint mousePoint, IPMUnknown* widget)
          switch (actionID.Get())
              case kExportActionID:
                  InterfacePtr<IIdleTaskThread> updThread(GetExecutionContextSession(), IID_IMWDUSYNCTASKTHREAD);
                  if (!updThread) return;


      // Thread class
      class MWDUSyncTaskThread : public CIdleTaskThread
        MWDUSyncTaskThread(IPMUnknown* boss);
        virtual ~MWDUSyncTaskThread(void) {}
        virtual const char* TaskName();
        virtual void UninstallTask();
        virtual void RunThread(uint32 flags);
      CREATE_PMINTERFACE(MWDUSyncTaskThread, kMWDUSyncTaskThreadImpl)
      MWDUSyncTaskThread::MWDUSyncTaskThread(IPMUnknown* boss) : CIdleTaskThread(boss)
      const char* MWDUSyncTaskThread::TaskName()
        return "MWSyncronizationThread";
      void MWDUSyncTaskThread::RunThread(uint32 flags)
        IDFile idfile(WideString("G:\\class_3year.gif"));
        IDocument* iDocument = GetExecutionContextSession()->GetActiveContext()->GetContextDocument();
        if (!iDocument) return;
        InterfacePtr<ISpreadList> iSpreadList(iDocument, UseDefaultIID());
        if (!iSpreadList) return;
        UID uid = iSpreadList->GetNthSpreadUID(0);
        IDataBase* db = ::GetDataBase(iDocument);
        UIDRef spreadRef(db, uid);
        InterfacePtr<ISpread> iSpread(spreadRef, UseDefaultIID());
        UIDList itemlist(spreadRef.GetDataBase());
        iSpread->GetItemsOnPage(0, &itemlist, kFalse);
        UIDRef graphicFrame = itemlist.GetRef(0);
        if (graphicFrame.GetUID() == kInvalidUID ||GraphicFrameHelper::LinkImage2(graphicFrame, idfile) != kSuccess)
      void MWDUSyncTaskThread::UninstallTask()


      // Replace the picture
      ErrorCode GraphicFrameHelper::LinkImage2(const UIDRef& frameUIDRef, const IDFile& filePath)
        ErrorCode status = kFailure;
             if (!FileUtils::DoesFileExist(filePath) || FileUtils::IsDirectory(filePath) == kTrue) break;
             InterfacePtr<IHierarchy> hier(frameUIDRef, UseDefaultIID());
             if (hier == nil) break;
             UID oldPageItem = hier->GetChildUID(0);
             URI fileURI;
             Utils<IURIUtils>()->IDFileToURI(filePath, fileURI);
             InterfacePtr<ICommand> importFileCmd(CmdUtils::CreateCommand(kImportAndLoadPlaceGunCmdBoss));
             if (!importFileCmd) break;
             InterfacePtr<IImportResourceCmdData> importCmdData(importFileCmd, IID_IIMPORTRESOURCECMDDATA);
             if (!importCmdData) break;
             importCmdData->Set(frameUIDRef.GetDataBase(), fileURI, kSuppressUI);
             if (CmdUtils::ProcessCommand(importFileCmd) == kFailure)   // InDesign crash
             const UIDList* itemList = importFileCmd->GetItemList();
             InterfacePtr<ICommand> replaceCmd(CmdUtils::CreateCommand(kReplaceCmdBoss));
             if (!replaceCmd) break;
             InterfacePtr<IReplaceCmdData> replaceData(replaceCmd, IID_IREPLACECMDDATA);
             if (!replaceData) break;
             replaceData->Set(frameUIDRef.GetDataBase(), oldPageItem, itemList->First(), kFalse);
             status = CmdUtils::ProcessCommand(replaceCmd);
        } while (false);
        return status;