Random Errors in ActionScript - Memory overflow?

戏子无情 提交于 2020-01-06 21:21:23

问题


We're developing an InDesign CS6 Extension with Adobe Flash Builder 4.6. I got strange errors in a JavaScript Injection, so I converted the JavaScript to Action Script and put it directly into my code. But the errors continue to appear.

This is the code:

var pageItem:PageItem = (component as BaseComponent).pageItem;
var frame:Frame = new Frame(pageItem);
var itemIsHidden:Boolean = !pageItem.visible;
var tempFile:File;
var container:Rectangle = InDesign.app.activeDocument.rectangles.add(InDesign.app.activeDocument.activeLayer); // (2)

try {
    pageItem.visible = true;
    var prefix:String = "TMP_IMAGE_CONTAINER";
    var bounds:Array = frame.convertToBounds();

    Log.log("Container id = " + container.id);
    Log.log("bounds = " + bounds);
    Log.log("frame.ax = " + frame.ax + ", frame.ay = " + frame.ay);

    container.name = prefix+container.id; // (3)
    container.geometricBounds = bounds; // (1)
    container.strokeWeight = 0;
    container.strokeColor = InDesign.app.activeDocument.swatches.item("None");
    container.fillColor = InDesign.app.activeDocument.swatches.item("None");
    container.visible = true;
    container.transparencySettings.blendingSettings.opacity = 100;

    // create a duplicate of the pageItem in the tmp container
    var copyItem:PageItem = pageItem.duplicate(InDesign.app.activeDocument.activeLayer);
    copyItem.transparencySettings.blendingSettings.opacity = 100;
    copyItem.locked = false;
    container.geometricBounds = bounds;
    container.move([frame.ax,frame.ay]); // (4)
    copyItem.visible = true;

    InDesign.app.select(copyItem);
    InDesign.app.cut();
    InDesign.app.select(container);
    InDesign.app.pasteInto();

    //InDesign.app.scriptArgs.setValue("container", prefix+container.id);

    // [...]

} catch (e:Error) {
    Log.log(e.toString());
    Log.log(e.getStackTrace());
} finally {
    if (container) {
        container.remove();
    }
        pageItem.visible = !itemIsHidden;
}

The log statements at the beginning are to make sure, the variables are defined at this point. However, I get errors all the time in a (seemingly) random manner: (1)

[INFO] [29:1786:739] [ImageExporter::export():65] Container id = 12818
[INFO] [29:1787:386] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [29:1787:931] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [29:1799:462] [ImageExporter::export():113] Error: Invalid value for set property 'geometricBounds'. Expected Array of 4 Units, but received null.

or (2)

Error: Cannot create page item. No valid parent found.
    at flash.external::HostObject/__call()
    at com.adobe.csawlib::CSHostObject/hostCall()
    at com.adobe.indesign::Rectangles/add()
    at ImageExporter/export()[...export/ImageExporter.as:58]

or (3)

[INFO] [14:843:201] [ImageExporter::export():65] Container id = 12818
[INFO] [14:843:202] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [14:843:202] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [14:843:239] [ImageExporter::export():114] Error: Invalid value for set property 'name'. Expected String, but received null.

or (4)

[INFO] [17:1025:895] [ImageExporter::export():65] Container id = 12818
[INFO] [17:1025:896] [ImageExporter::export():66] bounds = 0,0,70,526
[INFO] [17:1025:896] [ImageExporter::export():67] frame.ax = 334, frame.ay = 1197
[INFO] [17:1025:964] [ImageExporter::export():115] Error: Missing required parameter 'to' for method 'move'.
    at flash.external::HostObject/__call()
    at com.adobe.csawlib::CSHostObject/hostCall()
    at com.adobe.indesign::Rectangle/move()
    at ImageExporter/export()[.../export/ImageExporter.as:83]

The errors appear always while exporting the same object. We checked the syntax inside our extension and the objects in InDesign, but everything seems to be fine.

I'm new to Action Script but my common sense as developer tells me, that (1) bounds is an array with 4 entries (as stated in the log message) and (2) even if there is no valid parent, the extension should have crashed here every time (I use the same document every time).

It could be a memory overflow error (because the errors only appear in InDesign-Files with many objects) but I couldn't find an option to increase it.

Note: The Rectangle used in this class is a class from the Extend script API.

来源:https://stackoverflow.com/questions/30322899/random-errors-in-actionscript-memory-overflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!