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

How to fix stack overrun issue?

Explorer ,
Dec 19, 2017 Dec 19, 2017

Hi All,

I have got an alert for stack overrun while running InDesign script.stack overrun.png

Below is my code.

var myDoc=app.activeDocument;          

var outputINTT=File("E:\\2017\\Tools\\branches\\PR225_Auto_Pagination\\working\\indesign-scripts\\typesetting\\SupportScripts\\pagenation\\INDD\\FullDocument.intt");

//var textFrame=app.selection[0];

var reflowFrameLabelName="MainFrame";

var mainFrame=getFrame(myDoc.pages[0],"MainFrame");

//myDoc.pages[0].place(outputINTT,[mainFrame.geometricBounds[0],mainFrame.geometricBounds[1]],undefined,false,true);                      

mainFrame.place(outputINTT,false);

CheckingOverSet(reflowFrameLabelName);

function getFrame(myPage,labelString)

{

    var myTextFrames = myPage.textFrames;

    for (var i = 0; i < myTextFrames.length; i++) {

        if (myTextFrames.label.match(labelString))

            return myTextFrames;

        }

    }      

function CheckingOverSet(reflowFrameLabelName) {

    var lastPage = app.activeDocument.pages.lastItem();

    var lastPageTextFrames = lastPage.textFrames;

    for (var tf = 0; tf < lastPageTextFrames.length; tf++) {

        if (lastPageTextFrames[tf].overflows == true) {

            var overSetFrame = lastPageTextFrames[tf];

            var masterPageName = lastPage.appliedMaster.name;

            overSetFrame.select();

            var newPage = app.activeDocument.pages.add();

            OverrideMasterItems();

            var reflowPageTextFrames = newPage.textFrames;

            if (reflowPageTextFrames.length > 0) {

                var reflowFrame = getFrame( newPage,reflowFrameLabelName);

                if (reflowFrame == null) {

                    alert("The master page " + masterPageName + " is not having the TextFrame name " + reflowFrameLabelName + ". Script can't reflow the content to the page...")

                } else if (reflowFrame != $.global.undefined) {

                    try {

                        overSetFrame.nextTextFrame = reflowFrame;

                        if (reflowFrame.overflows) {

                            CheckingOverSet(reflowFrameLabelName);

                        }

                    } catch (e) {

                        alert(e)

                    }

                }

            } else {

                alert("The master page " + masterPageName + " is not having TextFrames. Script can't reflow the content to the page...")

            }

        }

    }

}

function OverrideMasterItems() {

    var allItems = app.activeDocument.pages[app.activeDocument.pages.length - 1].appliedMaster.pageItems.everyItem().getElements();

    for (var i = 0; i < allItems.length; i++) {

        try {

            allItems.override(app.activeDocument.pages[app.activeDocument.pages.length - 1])

        } catch (e) {}

    }

}

Thanks,

Prakash.C

TOPICS
Scripting
3.0K
Translate
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 ,
Dec 20, 2017 Dec 20, 2017

Did you identify the specific portion of the code that throws that error ?

I would look at your loops carefully because it's generally a good source of troubles.

Plus what's a pity is that you try/catch errors without logging the possible errors. You should at the very least use this kind of pattern. That would help you debugging…

try {

     //something that could throw an error

}

catch(err){

     $.writeln (err.line+"//"+ err.message );

}

HTH

Translate
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
Mentor ,
Dec 21, 2017 Dec 21, 2017

Stack overrun is usually caused by recursion - a function calling itself.

In your case that would be CheckingOverSet ...

Translate
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
Community Expert ,
Dec 22, 2017 Dec 22, 2017
LATEST

This is a classic. As Dirk mentioned, your CheckingOverset() is a recursive function. If the overset can't be resolved, your script keeps adding pages. The permanent overset state is usually caused by a large inline frame that doesn't fit the page or a long string that doesn't fit the measure. Long URLs are often a problem.

To cope with your problem, add a check: if the text frame on the previous page is empty, the frame is permanently overset and your script should stop. You could add a counter so that the script stops if you have e.g. 3 or 4 empty pages.

P.

Translate
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