Quantcast
Channel: Adobe Community : Popular Discussions - InDesign SDK
Viewing all articles
Browse latest Browse all 78596

How to prevent crashes - ITextModelCmds

$
0
0

Hi

 

In our plugin we substitute text defined by xml marker positions. The following code is working fine for the majority of our test cases, but for a specific combination of substitutions it fails with an access violation when calling RecomposeThruLastFrame.

I really hope somebody can give me a hint on modifying the following code to prevent crashes?

 

Thanks

 

Kind regards Toke

 

 

Code snippet (This is called lots of times within a loop):

 

ErrorCode status = kFailure; 

                    do {

 

                               InterfacePtr<IIDXMLElement> data = myTextStory->QueryXMLData(ref);

                              if(!data) break;

 

                              TextIndex delStart, delEnd;

                              Utils<IXMLUtils>()->GetElementMarkerPositions (data, &delStart, &delEnd);

 

                              InterfacePtr<ITextModel> textModel(myTextStory, UseDefaultIID());

                              if(!textModel) break;

 

  if (delStart < 0 || delStart >= textModel->TotalLength()) break;

 

                              if (delEnd-delStart < 1 || delEnd >= textModel->TotalLength()) break;

 

                              InterfacePtr<ITextModelCmds> textModelCmds(textModel, UseDefaultIID());

                              if(!textModelCmds) break;

 

  // Check for global errors

                              status = ErrorUtils::PMGetGlobalErrorCode();

                              if(status != kSuccess) break;

 

                              InterfacePtr<ICommand> delCmd(textModelCmds->DeleteCmd(delStart,delEnd-delStart));

                              status = CmdUtils::ProcessCommand(delCmd);

                              if(status != kSuccess) break;

 

  // Check for global errors

                              status = ErrorUtils::PMGetGlobalErrorCode();

                              if(status != kSuccess) break;

 

                              boost::shared_ptr<WideString> wide(new WideString(substitution));

                              InterfacePtr<ICommand> insertCmd(textModelCmds->InsertCmd(delStart, wide));

                              status = CmdUtils::ProcessCommand(insertCmd);

                              if(status != kSuccess ) break;

 

                              InterfacePtr<IFrameList> frameList(textModel->QueryFrameList());

                              if (!frameList) break;

 

                              InterfacePtr<IFrameListComposer> frameListComposer(frameList, UseDefaultIID());

                              if(!frameListComposer) break;

 

  // Check for global errors

                              status = ErrorUtils::PMGetGlobalErrorCode();

                              if(status != kSuccess) break;

 

                              frameListComposer->RecomposeThruLastFrame(); //See Table 94 in the programming guide


} while(kFalse);


Viewing all articles
Browse latest Browse all 78596

Trending Articles