Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 90000

Photoshop CC: Calling PIUGetInfoByIndex causes an exception when searching documents

$
0
0

I have a function call in an automation plug-in that searches through the documents opened in Photoshop and attempts to get the name of each document (to compare it to a name that is passed in).  When this piece of code gets hit, if Photoshop has two documents open with the same name, a crash occurs when it tries to get the document information by index.  Below is the code, and I will highlight where the crash is occurring.  Note that this crash does not occur in Photoshop CS5 or Photoshop CS6.  This crash occurs in Photoshop CC regardless of the Photoshop SDK used to compile the plug-in (I tried with CS5 and CC).

 

Apologies for the poor formatting.

 

//Find the document index.

int32 doc_index = -1;

if (num_documents > 0)

{

  if(params.in_doc_name.length() > 0)

  {

      string doc_name;

      char doc_name_holder[128];

      for (int32 doc_counter = 1; doc_counter <= num_documents && ! error; doc_counter++)

      {

      GetDocumentName(doc_counter, doc_name_holder);

      doc_name = doc_name_holder;

      if(doc_name.find(params.in_doc_name) != std::string::npos)

      doc_index = doc_counter;

      }

  }

  else

  {

      doc_index = num_documents;

  }

  //If we didn't find the document to export in the document names, perform the export on the last document.

  if(doc_index == -1) doc_index = num_documents;

}

 

//Gets the name of the document at the given index.

SPErr GetDocumentName(int32 document_index, char* doc_name)

{

  PIActionDescriptor result;

  sPSActionDescriptor->Make(&result);

 

 

  SPErr error =

  PIUGetInfoByIndex( <--- from PIUGet.cpp

  document_index,

  classDocument,

  0,

  &result,

  NULL);

 

 

  error = sPSActionDescriptor->GetString(result, keyTitle, doc_name, 128);

 

 

  if(result) sPSActionDescriptor->Free(result);

 

 

  return error;

}

 

 

<--- FROM PIUGet.cpp --->

//-------------------------------------------------------------------------------

//-------------------------------------------------------------------------------

SPErr PIUGetInfoByIndex(uint32 index,

  DescriptorClassID desiredClass,

  DescriptorKeyID desiredKey,

  void * returnData,

  void * returnExtraData)

{

  SPErr error = kSPNoError;

    PIActionReference reference = NULL;

    PIActionDescriptor result = NULL;

  PIActionDescriptor * data;

 

 

  if (returnData == NULL)

  error = kSPBadParameterError;

  if (error) goto returnError;

 

 

  error = sPSActionReference->Make(&reference);

  if (error) goto returnError;

 

  if (desiredKey)

  {

  error = sPSActionReference->PutProperty(reference,

  classProperty,

  desiredKey);

  if (error) goto returnError;

  }

 

  error = sPSActionReference->PutIndex(reference,

  desiredClass,

  index);

  if (error) goto returnError;

 

  error = sPSActionControl->Get(&result, reference);   <----------------- CRASHES HERE

  if (error) goto returnError;

 

 

  if (desiredKey)

  {

  error = PIUGetSingleItemFromDescriptor(result,

                                    desiredKey,

    returnData,

    returnExtraData);

  if (error) goto returnError;

  } else {

  data = (PIActionDescriptor *)returnData;

  *data = result;

  result = NULL;

  }

 

 

returnError:

 

 

  if (reference != NULL) sPSActionReference->Free(reference);

  if (result != NULL) sPSActionDescriptor->Free(result);

 

  return error;

}


Viewing all articles
Browse latest Browse all 90000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>