Dieuz Posted December 18, 2006 Posted December 18, 2006 (edited) I know there's alot of topic about this subject on the forum but no one seem to help me so I made this one. I just made a new script and I'm getting this Stack Overflow error. Sometime, the script can run fine during 6-7 hours without getting this error but sometime it happen after 15 min. I don't know exactly what to change to my script to correct this problem. Here's the basic of my script. There's alot of loops because it's a bot. It has to be able to run during an infinitive time. NEW SCRIPT, scroll down Edited December 19, 2006 by Dieuz
PaulIA Posted December 18, 2006 Posted December 18, 2006 I know there's alot of topic about this subject on the forum but no one seem to help me so I made this one. I just made a new script and I'm getting this Stack Overflow error. Sometime, the script can run fine during 6-7 hours without getting this error but sometime it happen after 15 min. I don't know exactly what to change to my script to correct this problem. Should I remove some functions? Should I remove the CALL on the function Restart but change it for what? Should I remove CALLs at all? Here's the basic of my script. There's alot of loops because it's a bot. It has to be able to run during an infinitive time. expandcollapse popup;Hotkeys HotKeySet("{HOME}", "Terminate") ; HotKeySet("{F2}", "Start") ; HotKeySet("{F4}", "Pause") ; ;Variables Global $Paused $ColorAttack = Pixelgetcolor(837,464) $ColorVictory = Pixelgetcolor(402,169) $Color5wins = Pixelgetcolor(595,387) $Trophyswon = 0 $ColorBug = Pixelgetcolor(840,467) While 1 sleep(100) Wend Func Start() ;Stuff here Call ("Restart") EndFunc Func Restart() ;Stuff here ;5 WINS If $Color5wins ="5911585" Then Call ("Winner") EndIf ;stuff here Call ("Restart") EndFunc Func Winner() ;stuff here Call ("Restart") EndFunc Func Pause() ;stuff here EndFunc Func Terminate() Exit(0) EndFunc oÝ÷ Ø-ëæ¬jëh×6Restart() Auto3Lib: A library of over 1200 functions for AutoIt
Dieuz Posted December 19, 2006 Author Posted December 19, 2006 (edited) I tought I had corrected it but I still have this stack overflow problem. expandcollapse popupWhile 1 sleep(100) Wend Func Start() ;stuff here, this function only happen once Restart() EndFunc Func Restart() While 1 Sleep(1500) *********************************** If Then ; stuff here Do ;stuff here Until ;stuff here Else ;stuff here If then ; happen like 1 time out of 1000 Restart() Else Do ;stuff here Until ;stuff here EndIf EndIf Wend EndFunc Func Pause() ;stuff here Endfunc Func Terminate() Exit(0) EndFunc *********************** = where im getting the stack overflow error Maybe there's something wrong in my script but I cannot figure it out. I dont understand why there's recursion because there's no call at all ( except one that is almost never used). Also, I dont stack any variables. Edited December 19, 2006 by Dieuz
PaulIA Posted December 19, 2006 Posted December 19, 2006 (edited) I tought I had corrected it but I still have this stack overflow problem. CODEexpandcollapse popupWhile 1 sleep(100) Wend Func Start() ;stuff here, this function only happen once Restart() EndFunc Func Restart() While 1 Sleep(1500) *********************************** If Then ; stuff here Do ;stuff here Until ;stuff here Else ;stuff here If then ; happen like 1 time out of 1000 Restart() Else Do ;stuff here Until ;stuff here EndIf EndIf Wend EndFunc Func Pause() ;stuff here Endfunc Func Terminate() Exit(0) EndFunc *********************** = is where im getting the stack overflow error Maybe there's something wrong in my script but I cannot figure it out.What part of "The problem is that Restart calls itself" did you not understand? Every time a function calls itself, it consumes part of the stack. That memory isn't returned to the system until the function exits. If you never exit the function by constantly looping within the function, you burn up the stack. Edited December 19, 2006 by PaulIA Auto3Lib: A library of over 1200 functions for AutoIt
Dieuz Posted December 19, 2006 Author Posted December 19, 2006 (edited) I will try to avoid calling. If the function constantly loop with While/Do/For does it consume the stack? If I do something like that, does it consume part of the stack? Func Restart() If blablablabla then Test() EndIf EndFunc Func Test() Restart() EndFunc Edited December 19, 2006 by Dieuz
ChrisL Posted December 19, 2006 Posted December 19, 2006 I will try to avoid calling. If the function constantly loop with While/Do/For does it consume the stack? If I do something like that, does it consume part of the stack? Func Restart() If blablablabla then Test() EndIf EndFunc Func Test() Restart() EndFunc That will do the same [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
Dieuz Posted December 19, 2006 Author Posted December 19, 2006 That will do the sameWhat will consume stack? While/Do/For or the function I just wrote?
ChrisL Posted December 19, 2006 Posted December 19, 2006 What will consume stack? While/Do/For or the function I just wrote?Look at this example http://www.autoitscript.com/forum/index.ph...st&p=263863This is the type of thing you will need to do.Your functions must be able to exit and return, if they just keep calling each other then they never return and your script will bomb out [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
Dieuz Posted December 19, 2006 Author Posted December 19, 2006 Thx for the link Chris! So If I am not calling at all, I should not get any recursion error right?
mikehunt114 Posted December 19, 2006 Posted December 19, 2006 (edited) It's been stated several times here, and several times in other topics that you have created. Take the advice that people are giving you and don't have Restart() call itself, ie. the following is recursive and will give you a stack overflow error:Func Restart() ;blah blah Restart() EndFuncLearn to write loops to do what you desire, recursion is very rarely needed. Please stop multi-posting this all over the forums. Take a look at some of the examples/links people have posted.Edit: typo Edited December 19, 2006 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
ChrisL Posted December 19, 2006 Posted December 19, 2006 Thx for the link Chris! So If I am not calling at all, I should not get any recursion error right? Here it is simplified, run it and you will see what it does expandcollapse popup$start = 1 $Restart = 2 $pause = 3 $terminate = 4 $job = Start() While 1 Switch $job Case $start $job = Start() Case $Restart $job = Restart() Case $pause $job = Pause() Case $terminate $job = Terminate() EndSwitch WEnd Func Start() ;stuff here, this function only happen once Msgbox (0,"","Start function",2) Return $Restart EndFunc Func Restart() $ans = Msgbox(4,"","Do you want to do some more?") If $ans = 6 then Return $start Else Return $terminate EndIf EndFunc Func Pause() ;stuff here Endfunc Func Terminate() Msgbox (0,"","OK Bye") Exit(0) EndFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
Richard Robertson Posted December 19, 2006 Posted December 19, 2006 Why are you using functions so much? It would be easier, and less recursive, if you would just make a main loop and use proper conditionals, it will not throw stack overflows like that.
Dieuz Posted December 19, 2006 Author Posted December 19, 2006 I'm using one main function, and 3 small one ( Start,Pause,Exit) HotKeySet("{HOME}", "Terminate") ; Terminates the Script when HOME is pressed HotKeySet("{ENTER}", "Start") ; Run the Script when ENTER is pressed HotKeySet("{SPACE}", "Pause") ; Pause the Script when SPACE is pressed
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now