script "dies" after several hours runing

Get help with using AutoHotkey and its commands and hotkeys
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

script "dies" after several hours runing

26 Nov 2018, 06:42

Hello.

So, i've built a website checking tool, and it works nicelly.. Thing is, it just dies after some hours.
That just doesn't work as you might imagine, if the objective is to keep an eye on things.
And by "dies" i mean i've seen it go down, it just disapears while it is working and closes itself.

Can someone please take a look and see what might be causing this?
I've been banging my head for days now..

(removed)

:? :?
Last edited by Portwolf on 26 Nov 2018, 18:28, edited 1 time in total.
swagfag
Posts: 4092
Joined: 11 Jan 2017, 17:59

Re: script "dies" after several hours runing

26 Nov 2018, 11:11

well, i doubt any one can debug this, other than u urself, obviously, but after taking a cursory look at it, i reckon it might have something to with the liberal usage of Gosubs triggering a user callback exception(0xc000041d)
let it run and check the event logs once it crashes: event viewer -> windows logs -> application and check the exception code its giving u
example, if u never return:

Code: Select all

MyFunc() {
    static i := 0, init := MyFunc()

    MyLabel:
        ToolTip % "Blow me up..." ++i
        Gosub MyLabel
    return
}
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: script "dies" after several hours runing

26 Nov 2018, 12:50

It's not GoSubs, it's init := MyFunc() , though swagfag is right,you can only ever call the function itself so many times,before a stackoverflow... Do this instead, init := !init ? MyFunc() : "".

Example of a stackoverflow:

Code: Select all

x()

x(){
	Static
	i := i ? (i+1) : 1
	ToolTip % i
	x()
}
live ? long & prosper : regards
swagfag
Posts: 4092
Joined: 11 Jan 2017, 17:59

Re: script "dies" after several hours runing

26 Nov 2018, 13:23

theres nothing wrong with static init := MyFunc(). it calls itself once at script startup, avoiding the need to call it explicitly. it doesnt do so recursively, if thats what ure thinking
SOTE
Posts: 1198
Joined: 15 Jun 2015, 06:21

Re: script "dies" after several hours runing

26 Nov 2018, 13:58

Portwolf wrote:
26 Nov 2018, 06:42
Hello.

So, i've built a website checking tool, and it works nicelly.. Thing is, it just dies after some hours.
That just doesn't work as you might imagine, if the objective is to keep an eye on things.
And by "dies" i mean i've seen it go down, it just disapears while it is working and closes itself.

Can someone please take a look and see what might be causing this?
I've been banging my head for days now..

:? :?
Taking a quick look, I noticed that a number of your subroutines/labels don't have a "return" after them. This can cause unexpected results, because AutoHotkey will keep going down to the next label, after the next, and processing commands until it hits a "return", unless you have it in a loop or waiting for input or a result.

https://autohotkey.com/docs/commands/Return.htm

In this pseudo code example, such a script design can have all kinds of problems. You are telling AutoHotkey to jump to a label 3, but it will keep executing until it hits the "return" at label 4. To make it worse, your gosubs or goto can have the code jumping all over, but the program will execute other unwanted labels or subroutines because there is no "return" or code logic to stop it.

Code: Select all


code

Label 1:

code

gosub, Label 3

Label 2:

code

Label 3:

code

Label 4:

code

return

You might want to organize your code where every label has a return, unless you want it to keep running downwards or exit the program (like GuiClose and ExitApp). If you want sections of code to execute in sequence, one after the other, then you might want to organize them under the same subroutine.

When Label 1 one jumps to Label 3, after Label 3 is done, it will then "jump back" and return to Label 1 or from the point where it started the jump from. Unless of course, you specifically want the program to blend labels together by letting it execute downwards to the next label or group of labels. Making sure subroutines are separate from each other, is what makes gosub much safer to use. And it stops unexpected results.

Code: Select all


code

Label 1:

code

gosub, Label 3

return

Label 2:

code

return

Label 3:

code

return

Label 4:

code

return

GuiClose:

ExitApp
Last edited by SOTE on 29 Nov 2018, 12:51, edited 3 times in total.
swagfag
Posts: 4092
Joined: 11 Jan 2017, 17:59

Re: script "dies" after several hours runing

26 Nov 2018, 14:12

another approach to help u narrow it down(though it could be a bit labor intensive, but shouldnt necessarily be all that bad with a bit of text editor kung fu) would be to log every line the script is running and check what the last line was, when it crashed
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: script "dies" after several hours runing

26 Nov 2018, 18:30

Thank you all for your help.
Seems like there is some code optimization i need to get into....

Best regards!
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: script "dies" after several hours runing

26 Nov 2018, 20:37

swagfag wrote:
26 Nov 2018, 13:23
theres nothing wrong with static init := MyFunc(). it calls itself once at script startup, avoiding the need to call it explicitly. it doesnt do so recursively, if thats what ure thinking

I stand corrected, apparently Gosubs have much like functions a limit of sorts(1673 'recursive' calls WITHIN FUNCTIONS),go figure. Using a simple GoTo solves the issue though.
live ? long & prosper : regards

Return to “Ask For Help”

Who is online

Users browsing this forum: alexsu, Muzzy, Rohwedder and 32 guests