script crashes with stack overflow when jumping out of a while loop several times
Having the same issue. Runs the whole script top to bottom 8 times, but the ninth run will have stack overflow error the first time it enters a while loop. The repeat of the script is a goto like in the example above. Is there a better way to loop back to the beginning of a script? Or some way to avoid this issue?
This may have been fixed if it was ever an issue. I resolved my issue by using 'call/return' instead of 'goto'. I have a 400+ line TTL file that consistently caused a 'Stack overflow' error on the 9th loop back to the top of the file. After refactoring it to use 'call' and 'return' I am on the 12th run without issue. I'll come back and update this if it crashes on the 1000th run or something.
Your 'goto MAIN' commands may have been the issue. Each 'goto MAIN' may not close/release the previous instance of 'MAIN', so the stack may pile up with each goto you add. Like MAIN nested into MAIN into MAIN in a chain until the stack overflow happens. Try something like what I edited below. I see this is years old, but leaving this here in case anybody else like me runs into this issue and can't google up a solution.
It splits up the script into functions that can be called with 'call <label>' and returns to the line they were called from with 'return'. No need to 'goto' anywhere. 'goto' commands can be used for error handling and debugging but aren't good for looping because of this.
;#### MAIN ####
num = 0
until num=1000
int2str STRN num
title = 'number of loops before stack overflow: '
strconcat title STRN
settitle title
call checkthelink
call addtocounter
enduntil
exit
;#### Functions ####
:addtocounter
num = num+1
return
:checkthelink
maxtime = 2
while maxtime>1
testlink
if result=2 then
return
endif
statusbox 'port not available!' 'State'
pause 1
closesbox
maxtime = maxtime-1
endwhile
return
For the algorithms: Tera Term Macro Loop Goto Call Return Stack Overflow While Until
num = 0
:MAIN
num = num+1
int2str STRN num
title = 'number of loops before stack overflow: '
strconcat title STRN
settitle title
maxtime = 2
while maxtime>1
endwhile
:TEST_END
pause 1
goto MAIN