Re: why my script is destroyed?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: why my script is destroyed?

20 Mar 2018, 13:40

I do not know. but maybe you are incorporating a few logging functionalities. for example at this point. maybe interesting.
or/and a simple message box. Msgbox,`n (%A_LineFile%~%A_LineNumber%)
gameba wrote:...

Code: Select all

ESC::
{
	ExitApp
	return
}
Mod edit: Moved post due to topic duplicate, OP of this topic is the post below.
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

Any way to create a recursive function infinite does not crash?

20 Mar 2018, 20:50

I created a recursive function infinite below:

Code: Select all

#include Vis2.ahk
CoordMode, mouse, screen
CoordMode, Pixel, screen
global bookid:=0
pToken := Gdip_StartUp()
funcOCR(){
	regText := OCR([28, 170, 250, 90])
	;OutPutDebug, % regText "chil"
	
	if (InStr(regText,"chil")){
		sleep 1000
		click 500,603
		sleep 2000
		funcOCR()
		;sendInput {F1} I tried sendInput but It also crashed
		return
	}else{
		click 37,603
		sleep 2000
		funcOCR()
		;sendInput {F1} I tried sendInput but It also crashed
		return
	}
}
F1::
{
	funcOCR()
	return
}
ESC::
ExitApp
It works great for 30 min-1 hours, then it was crashed, The icon AutoHotkey on the toolbar disappears, no error message, no notification

I received error in Windows Event Viewer:

Code: Select all

Faulting application name: AutoHotkey.exe, version: 1.1.28.0, time stamp: 0x5a7f9e69
Faulting module name: gdiplus.DLL_unloaded, version: 10.0.16299.248, time stamp: 0x3e35f305
Exception code: 0xc0000005
Fault offset: 0x00000000000013e3
Faulting process id: 0x2928
Faulting application start time: 0x01d3c0ad66dcb756
Faulting application path: C:\Program Files\AutoHotkey\AutoHotkey.exe
Faulting module path: gdiplus.DLL
Report Id: e28afa19-b5d0-410c-a0ed-a85c9016fa92
Faulting package full name: 
Faulting package-relative application ID:
I think the main cause of the crash is the infinite recursive function.
So, I want to know Any way to create a recursive function infinite does not crash?
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Any way to create a recursive function infinite does not crash?

20 Mar 2018, 21:18

I guess that you are causing a stack overflow or a memory leak...

But, where is the need for a recursive function here anyway? It can never end and return or break out. The function has neither variable parameters, nor a return value. There are not even varying variable contents (except the return value of OCR(), I assume) and you want to run the function again, anyway (why put it into the if and the else branch?). I really don't see any reason for a recursive funtion in the first place. You just want a series of normal fuction calls, it seems.

Why not just use a timer (see SetTimer) or a loop instead of a recursive function?
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Re: why my script is destroyed?

20 Mar 2018, 21:26

I think a merge of two topics went wrong... perhaps a mod can clean that up.
Edit: ah , there's a note - well, never mind.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Lamron750, Rohwedder and 270 guests