InDesign crash 0xC0000005 Access Violation
I have a client that is using automation to generate a pdf proof from an idml template. I am migrating their current OSX box to a virtual windows environment. There is an ExtendScript that runs and removes empty place holder text ranges that was taken directly from the working OSX machine. The template file that is causing the crash was created with nested TextFrames to keep text in the left column but allow it to shift up the page as the empty ranges are removed. As the script runs and removes empty lines, the lines below will shift up which does not leave empty space where the line was removed. This is the desired behavior since there are various combinations of line items that may or may not be used on the template. So any unused (empty) ones will be removed and all others will shift up.
This same template runs fine in their existing OSX system, but crashes on the windows machine when the script is ran. The crash does not happen on the same line of code and in some cases the script finishes completely before the crash. If I remove the nested TF's and recreate them outside the parent, so all TF's are at the same level, then it does not crash. Unfortunately, this is not a viable solution. As the replacement script runs the text shifts up (as it should) except for the replaced TF's that are now absolutely positioned where they were originally placed. The file can be opened in idml or indd format and it doesn't seem to matter.
I have tried various things to resolve this including installing updates, reducing the U.I. to bare minimum options/visible toolbars, rebooting, closing/re-opening the document, settings vars to null and calling $.gc(), $.sleep() to hopefully give GC time, and increasing the virtual box memory to 8GB with no luck. Breaking the tasks up into chunks and closing/re-opening the document between processing the chunks seemed to help for awhile but the issue is back in full force.
ExtendScript versions (same on both machines):
ExtendScript 4.5.5
ExtendScript UI 6.2.2
ExtendScript Toolkit 4.0.0.1
Working Legacy Setup:
OSX Yosemite 10.10.5 x64 / 2.4GHz Intel Core 2 Duo / 8GB RAM
Indesign CS4 6.0.6 x86 (CC, CS2, CS3 also installed)
Current Server Details:
Windows Server 2016 Datacenter x64 (virtual) / Intel Xeon 2.4 GHz / 4 GB RAM (tried 8gb)
Indesign CC 2017 12.0.0.81 x64
Event Log Data:
Faulting application name: InDesign.exe, version: 12.1.0.56, time stamp: 0x58c988ec
Faulting module name: APPFRAMEWORK.RPLN, version: 12.1.0.56, time stamp: 0x58c98b1f
Exception code: 0xc0000005
Fault offset: 0x00000000000c78f1
Faulting process id: 0x7d94c
Faulting application start time: 0x01d3485e6e6a0526
Faulting application path: C:\Program Files\Adobe\Adobe InDesign CC 2017\InDesign.exe
Faulting module path: C:\Program Files\Adobe\Adobe InDesign CC 2017\Required\APPFRAMEWORK.RPLN
Report Id: cc201fe4-f86c-4399-bc05-9f0d816d2373
Faulting package full name:
Faulting package-relative application ID:
Empty placeholder range replacement script:
$.gc();
ScriptPreference.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
var doc = app.activeDocument;
var tf = [];
var replacementMarker = '«»';
/*
//remove nested text frames that may cause 0xC0000005 Access Violation Fault.
var lc = 0;
for(var i=0; i < doc.layers.length; i++) {
for(var j=0; j < doc.layers.textFrames.length; j++) {
while(doc.layers.textFrames
.textFrames.length) { var textFrame = doc.layers.textFrames
.textFrames.lastItem(); textFrame.duplicate([textFrame.geometricBounds[1], textFrame.geometricBounds[0]]);
textFrame.remove();
if (lc > 999999) { alert('infinite loop!'); i=j=lc; break; } //just in case
}
}
}
*/
for (var i = 0; i < doc.allPageItems.length; i++) {
var item = doc.allPageItems;
try {
if (item.getElements()[0].constructor.name === 'TextFrame') {
tf.push(item);
}
} catch (e) {
$.writeln("ALERT1: " + e.message);
}
}
for (var i = 0; i < tf.length; i++) {
if (!tf || !tf.parentStory || !tf.parentStory.contents){
tf = null; $.gc(); $.sleep(100);
continue;
}
var ranges = [];
var content;
try {
content = tf.parentStory.contents.toString();
} catch (e) { }
if (content != '' && content.indexOf('[[') > -1) {
var range_start = false;
var range_end = false;
var range_startB = false;
var range_endB = false;
for (var j = 0; j < tf.parentStory.characters.length; j++) {
if (tf.parentStory.characters
.contents.toString() == '[' && (j+1) < tf.parentStory.characters.length && tf.parentStory.characters[j+1].contents.toString() == '[') {
range_start = j;
range_startB = true;
}
if (tf.parentStory.characters
.contents.toString() == ']' && (j+1) < tf.parentStory.characters.length && tf.parentStory.characters[j+1].contents.toString() == ']') {
range_end = j+1;
range_endB = true;
}
if (range_startB && range_endB) {
var _range_content = tf.parentStory.texts.itemByRange(tf.parentStory.characters[range_start], tf.parentStory.characters[range_end]);
if (_range_content.characters && _range_content.contents.toString().indexOf(replacementMarker) == -1) {
rg = tf.parentStory.texts.itemByRange(tf.parentStory.characters[range_start], tf.parentStory.characters[range_end]);
rg.contents; // DO NOT REMOVE. can't figure out why but this is necessary.
if (rg) {
ranges.push(rg);
}
}
range_startB = false;
range_endB = false;
_range_content = null; $.gc(); $.sleep(100);
}
}
}
for (var j = 0; j < ranges.length; j++) {
try {
ranges
.remove(); } catch (e) {
$.writeln("ALERT2: " + e.message);
}
}
ranges = null;
content = null;
tf = null;
$.gc(); $.sleep(100);
}
