9 Replies Latest reply on Mar 30, 2016 7:24 AM by TenguNagpo

    CS3 / Javascript -> Script Error 27: Stack overrun

    Hans Stössel Level 1

      Hi

       

      I have a script who is running all the time (like an Idle). This script calls a method in my own plugin, this method execute an action in my plugin. During this action, I call another Javascript to checkout a document from a content management system.

       

      This means:

      - A running script (Idle) calls a method in my plugin written in C++

      - The plugin calls another Javascript to checkout the document while the first plugin (Idle) is still runnung.

       

      This generates an error 27, stack overrun. I have tried several possibilities (with and without a main function, with and without #targetengine and so on), but always the same error.

       

      - What can I do?

      - Is it possible to run another script during the execution of one?

      - How can I do that?

      - Can I run two Javascript in her own environments? I mean own stack, own main and so on...

       

      Thanks for any hint.

      Hans

        • 1. Re: CS3 / Javascript -> Script Error 27: Stack overrun
          John Hawkinson Level 5

          This is probably an SDK level problem.

           

          I assume you've tried having both the idle javascript and the child javascript of the plugin run in different #targetengines?

          E.g. one in #targetengine session and the other in #targetengine plugin.

           

          Perhaps a workaround would be for your plugin to return a javascript to the idle loop that is executed there. Or maybe somethin with BridgeTalk.

           

          Just guessing here.

          • 2. Re: CS3 / Javascript -> Script Error 27: Stack overrun
            Harbs. Level 6

            It's kind of hard to diagnose such a problem, especially not knowing 

            all the details of your setup.

             

            Do you know which script causes the error?

             

            If your script is being parsed (and creating new JS objects) on every 

            idle event, you could easily be causing InDesign to run out of memory.

             

            Try making sure that you parse the script(s) only once...

             

            Make sure that you keep the writing of global variables to the bare 

            minimum (i.e. only once -- and keep those in memory).

             

            From my experience, I think you are best off (in terms of performance 

            and memory management) loading functions as global function (not local 

            ones) and making sure they are loaded only once per session.

             

            HTH

            Harbs

            • 3. Re: CS3 / Javascript -> Script Error 27: Stack overrun
              Harbs. Level 6

              John Hawkinson wrote:

               

              This is probably an SDK level problem.

              Yes, and no.

               

              The fact of the matter is: most people know the C++/SDK or scripting. My guess is, the number of developers mixing the two in a meaningful way is very small.

               

              This appears to be a question on mixing scripting and C++ which is for the most part, uncharted territory...

               

              Harbs


              • 4. Re: CS3 / Javascript -> Script Error 27: Stack overrun
                Steven.. Level 3

                The only time I came across this issue, was when an #include file included the file including it.

                • 5. Re: CS3 / Javascript -> Script Error 27: Stack overrun
                  Dirk Becker Level 4

                  John is right, this is more of a plugin/SDK question, I would have expected it in that forum first hand.

                   

                  Hans has cross posted this question into a swiss/german scripting forum with more details, and I've given a few suggestions. It broils down to the fact that the plugin access to scripting in CS3 had to address the JavaScript scripting subsystem rather than talk to a specific engine. And my strong guess is that the RunFile function triggered by the idle task of the first plugin is not reentrant so the second plugin can not invoke a method the same way.

                   

                  My suggestions, in brief: upgrade to CS4 where engines are independently addressible. Alternatively, one can try the other methods to invoke the script - RunScript rather than RunFile, or even use the callback mechanism that underlies the event listener registration. Easily accessible from the same interface class.

                   

                  Of course for the reentrancy problem I would not expect a Stack overrun error, so maybe it is not reentrancy at all but just the obvious - the second plugin calling itself in recursion. A breakpoint should easily tell.

                   

                  Dirk

                  • 6. Re: CS3 / Javascript -> Script Error 27: Stack overrun
                    Harbs. Level 6

                    I find it hard to believe that he needs to upgrade to CS4 for this.

                     

                    I have an awful lot of event driven scripts. I rarely use idle events 

                    because it adds a lot of overhead. When I do use idle events, it's 

                    generally for short periods of time. I do have scripts (quite 

                    complicated ones) which run very often. I have had problems with 

                    errors I don't remember if it was stack overrun, or just plain old out 

                    of memory errors. What I described above was how I solved the problem.

                     

                    FWIW, I'm sure you can run scripts in specific scripting engines via C+

                    + in CS3 as well. I don't know the details, but APID has the 

                    facilities to run scripts in specific engines -- in CS3 as well. The 

                    new commands in CS4 definitely help in terms of memory -- most 

                    specifically with kFastUndoEntireScript, but I have not found an event 

                    driven script that will not work in CS3 -- as long as the functions 

                    are created as global "static" functions.

                     

                    Harbs

                    • 7. Re: CS3 / Javascript -> Script Error 27: Stack overrun
                      Dirk Becker Level 4

                      Harbs,

                       

                      there is no need to upgrade to CS4, it was just a suggestion to keep the software up to snuff, for a feature that definitely has improved. Besides I mentioned plenty alternatives, including doubts whether the problem was reentrancy at all or just recursion.

                       

                      On the other hand let me strongly support your general suggestions on memory management, also considering an unrelated project that I recently inherited ...

                       

                      Dirk

                      • 8. Re: CS3 / Javascript -> Script Error 27: Stack overrun
                        Harbs. Level 6

                        Hi Dirk,

                         

                        I took a look at the thread on hilfdirselbst (using google 

                        translate)

                         

                        It does look like there's much more involved than mentioned here, and 

                        it does look like an SDK issue.

                         

                        I think I'll stay away from commenting on issues that I'm not very 

                        clear on...

                         

                        Harbs

                        • 9. Re: CS3 / Javascript -> Script Error 27: Stack overrun
                          TenguNagpo

                          > The only time I came across this issue, was when an #include file included the file including it.

                           

                          This seems the correct source of problem, as I've get rid of stated above issue when by deleting the cross-including the jsx files in ae extendscript