Parser stack overflow

Discussion in 'KONTAKT: Sampling, Programming & Scripting' started by Nickie Fønshauge, Sep 11, 2006.

  1. :?: :?: :?:
    Why, oh why do I keep getting "Parser stack overflow" error messages in K2's script editor? :cry: I can sometimes narrow the "culprit" down to "1" perfectly legitimate source line. If I remove this (not necessarily the same line each time), everything is fine.

    Are 4340 lines of compiled code too many? I find this hard to believe.

    Any ideas, please :!:
     
  2. kotori

    kotori Senior Member

    1,328
    9
    Apr 15, 2006
    Sweden
    Hi Nickie,
    I remember seeing this error message once, but I can't remember the context. Could you please send the line where the error is reported along with a couple of lines before and after. Could it be that you have nested too many block statements (like if, select, while) inside each other? :???:

    Cheers,
    Nils
     
  3. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Hi Nils,

    It is not one particular line. If I compile with compression, it is one line, and if I compile without compression it is another line. And when I have narrowed the problem down to 1 line, I can remove any one of various lines, that correct the problem.

    Last time I compiled without compression, the error ocurred in


    {begin Shift_information}
    $info_pointer := ($info_pointer + 1) mod $info_length
    @_info_line := ""
    $_i := $info_pointer
    while ($_i <= ($info_length - 1))
    @_info_line := @_info_line & !info[$_i]
    inc($_i)
    end while
    $_i := 0
    while ($_i <= ($info_pointer - 1))
    @_info_line := @_info_line & !info[$_i]
    inc($_i)
    end while
    set_text($information,@_info_line)
    {end Shift_information}

    at the boldfaced line. This is the "on init" block. There are no surrounding blocks except "on init".

    The source code reads:

    function Shift_information
    ``````declare global info_pointer
    ``````declare @info_line
    ``````declare i
    ``````info_pointer := (info_pointer + 1) mod info_length
    ``````@info_line := ""
    ``````for i := info_pointer to (info_length - 1)
    ````````@info_line := @info_line & !info
    ``````end for
    ``````for i := 0 to (info_pointer - 1)
    ````````@info_line := @info_line & !info
    ``````end for
    ``````set_text(information,@info_line)
    ````end function
     
  4. Dynamitec

    Dynamitec Senior Member

    1,072
    3
    May 12, 2006
    Hi Nickie,

    i got this error once too.

    There are some problems in KSP:

    - the on init callback may only have limited number of lines (don't know the number anymore, around 1000 i think)
    - if you have too much UI Elements or too much variables this error may occure too. I got this once i had more than 80 UI Elements.

    But: i wasn't sure if this problem was there due to the number of variables or the number of lines in the on init callback! (Or both: more variables => more declares in "on init")

    What can you do? Try to minimize lines in on init callback, try to declare NO local variables (since they have to be declared all in "on init"). Try to use for example i,j,k for every loop you use, etc...

    See what i mean? You declare i in this function. If you have 10 functions you'll ad 10 lines of code to your "on init" callback. If you have 3 local loop counter variables in each function you add 30 lines to on init. I know code gets better readable if you do those local declares. It's a pitty those limitations of KSP make a lot of Nil's work almost useless in big projects :(

    This was one of the most anoying error messages i got. Because i had to rewrite a lot. But after all: now i try to keep the size of the "on init" callback as small as possible.

    Somewhere there should be a thread were i already posted this (i think it was in the "welcome back big bob" thread.

    I hope i could help a little bit.
     
  5. Dynamitec

    Dynamitec Senior Member

    1,072
    3
    May 12, 2006
    BTW: Could you please send the number of lines in your "on init" callback and the number of variables you use? Because if you do, i can say for sure if this is your problem.

    What i really hate about NI and KSP: they had set some limits and nobody knows these limits! How many variables may be declared? How many ui elements? How many callbacks? How many lines per callback? It's really anonying!
     
  6. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Hi Benjamin,

    I have the nasty feeling, you are right. If you are, it is really bad news. :sad: There are 1485 "on init" lines in the uncompressed compiled code and 1130 in the compressed, and 384 variables. I'll try and reduce the size of "on init". Thank you for your help, both of you. :smile:
     
  7. kotori

    kotori Senior Member

    1,328
    9
    Apr 15, 2006
    Sweden
    I think I found the problem :smile:. It seems that the number of top-level statements (or statements at the same level) is restricted to about 995. However, you can work around this by introducing some artificial nesting. Eg. change this:

    Code:
    line1
    line2
    ...
    line1500
    into:
    Code:
    if (1=1)
      line1
      line2
      ...
      line750
    end if
    if (1=1)
      line751
      line752
      ...
      line 1500
    end if
    Cheers,
    Nils
     
  8. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    I'll try your solution. Thanks!

    Right now I am struggling with a (declared!) variable, which Kontakt claims is not declared. Yeah, right! :evil:
     
  9. kotori

    kotori Senior Member

    1,328
    9
    Apr 15, 2006
    Sweden
    You might want to watch out for empty if-statements (commented out code counts as empty) and assigning to builtin variables. I think there are some bugs related to these. Good luck!
     
  10. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Thanks.

    In this case it is the variable carrying the value of a "set_controller" statement. The statement has been parsed successfully before, so obviously the problem is somewhere else, possibly far away from the error line. :roll:
     
  11. Thonex

    Thonex Senior Member

    Wow Nickie... over 1000 lines for an init... what are you working on?

    Cheers,

    T
     
  12. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Version 2 of the G Strings script for the Garritan Solo Strings. I am improving the GUI and adding some new features. It keeps growing and growing and... Apparently I can't stop getting ideas for new features :lol:
     
  13. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Well, I finally got rid of the "parser stack overflow" messages. Oddly enough with the same variables and almost the same number of compressed "on init" lines (1112 against the 1130, that caused trouble). I just basically shuffled everything around.
     
  14. Thonex

    Thonex Senior Member

    Heh... the ol' software equivalent to kicking it :lol:
     
  15. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Yeah, something like that - if only it was as easy as kicking :smile: The kicking took me the better part of a day - "The long Kick Goodnight"! :wink:
     
  16. Dynamitec

    Dynamitec Senior Member

    1,072
    3
    May 12, 2006
    Hi Nickie, i'm glad to hear that you've managed it...and: thanks Nils for figuring out what exactly is the problem. Amazing KSP :) It's good to know the limits to get around them.
     
  17. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Yes, indeed. It would be a time saver, if the limits were better documented.
     
  18. kotori

    kotori Senior Member

    1,328
    9
    Apr 15, 2006
    Sweden
    Another cause of this problem might be initializing variables to non-constant values. It seems that Kontakt doesn't always report this problem, and in some cases it causes declared variables to be considered undeclared. Please split declarations and assignments to two different rows, eg:
    declare $x := find_group("test")
    change into:
    declare $x
    $x := find_group("test")
     
  19. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Yes, I did figure this out eventually - after I had spent a lot of time moving assignments to declaration lines in order to reduce the number of lines :wink: :roll: But thanks anyway :smile:
     
  20. OP
    OP
    Nickie Fønshauge

    Nickie Fønshauge Senior Member

    Nils, I just tried your artificial nesting idea, but, alas, it doesn't seem to work - back at square one :cry:
     

Share This Page