• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ExtendScript CEP on ID 18.1: app.open() crashes when reopening file

Community Beginner ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

For the purpose of templating, we have scripts that sometimes have to close and reopen the same file multiple times. When ran from the scripts panel, this works fine. When called from a CEP extension, the same procedure causes a crash. I discovered this while trying to port some aforementiond scripts to a CEP extension panel to improve usability.

 

I have been able to reproduce the bug, consistently and on multiple machines including a fresh install, with variations on this code:

 

var fileToReopen = new File(app.activeDocument.fullName);
// var fileToReopen = new File("path/to/some/file.indd"); //// makes no difference
app.activeDocument.close();
// $.gc() //// makes no difference
// $.sleep(1000 //or 5000 or 10000)  //// makes no difference
// for (var i=0; i<someArrayOfOtherFiles.length; i++) {
// app.open(someArrayOfOtherFiles[i]);
// app.documents[0].close();
// } //// do a bunch of other stuff, makes no difference!
app.open(fileToReopen); <---- crashes every time with exception c0000005 ERROR_ACCESS_VIOLATION

 

So, in effect, it can be caused with just 3 lines:

 

var fileToReopen = new File(app.activeDocument.fullName);
app.activeDocument.close();
app.open(fileToReopen); <---- exception c0000005 

 

These same 3 lines produce the intended result when called inside a script that's executed from the Scripts Panel. When called from the host (jsx) side of a CEP extension, it crashes InDesign. Doesn't matter if the call is automatic (one-time on load) or triggered by a UI or other event.

 

Other than inserting sleeps and running the gc to try and make sure it's not a race condition or stale memory, I haven't thought of any other bandaids yet. I have found other posts talking about this same issue going back to 2017, so it seems like it's been unresolved for over 5 years. Those other posts, such as this one had no working solutions or workarounds.

 

There is a workaround that does work, in case anyone needs it:

var file = new File("some/path");
// Instead of:
app.open(file);
// Do this: 
file.execute();

 

I'm not sure why doing it this way works when the other way doesn't. 

 

I hope this is able to help someone. In the meantime, consider this an open bug report until the app.open() call is fixed. That should be the proper way to open a InDesign file from CEP. Using File.execute() is a bit like climbing up the gutter to avoid taking the stairs.

TOPICS
Bug , Scripting

Views

570

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Mar 04, 2023 Mar 04, 2023

Is this the same as the regresion bug described here:  https://adobedevs.slack.com/archives/C1FFZQSJZ/p1676909606946019 if so email wwds@adobe.com, that might be the fastest route...

Votes

Translate

Translate
Community Expert ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Hi @Memorial0101, have you reported this issue as a CEP bug? @ErinF where is best place for Memorial0101 go to explore this issue?

- Mark

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

First of all, I can confirm the crash.

Second of all, reporting this as a bug is a good thing to do.

Fact that File.execute() works is interesting as it could mean that app.open/app.close conflict in the context of executing the jsx through CEP. As execute() probably rely on some OS internals, it may be on a different thread explaining why it works. It's a wild guess and I might be way out wrong here.

 

Anyway, one may question your need to close/reopen a doc. Can you say more about this need? It doesn't seem like a natural procedure to me.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

LATEST

Is this the same as the regresion bug described here:  https://adobedevs.slack.com/archives/C1FFZQSJZ/p1676909606946019 if so email wwds@adobe.com, that might be the fastest route...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines