How to find reason for crash every few weeks

Report problems with documented functionality
VarunAgw
Posts: 25
Joined: 05 Jan 2016, 11:51
Contact:

How to find reason for crash every few weeks

15 Feb 2018, 07:34

I am heavy user of AHK with 2000+ lines of personal scripts/hotkeys along with around a dozen of library. My problem is AHK crash every few days/weeks. Sometime not from weeks, sometime twice in a day.

Since it happens very rarely, it's very hard for me to determine what cause it and fix the relevant code in my script. How can I determine what causes it?

Also is there any way to auto restart it whenever it crash? It happens very rarely so I won't mind if restart automatically itself.
Ravenlord
Posts: 14
Joined: 19 Jan 2018, 03:43

Re: How to find reason for crash every few weeks

15 Feb 2018, 08:22

You can do second script which check for example every 1min if win exist, if not then run script.

Without any code we can only guess why it's crashing. Maybe lost connection to network drive which is required for your script, missing required file, maybe bad var. Who knows :)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to find reason for crash every few weeks

15 Feb 2018, 14:48

- In what way is it crashing? Does it show an error message? Does it 'forget' the hotkeys?
- You could set DetectHiddenWindows to On, and use a Loop, with WinWaitActive, and ahk_class AutoHotkey to identify which scripts are open. You could use PostMessage/WinClose to close or Process Close to force close a script.

Code: Select all

q:: ;list AutoHotkey scripts
DetectHiddenWindows, On
WinGet, vWinList, List, ahk_class AutoHotkey
vOutput := ""
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	WinGetTitle, vWinTitle, % "ahk_id " hWnd
	;WinGetClass, vWinClass, % "ahk_id " hWnd
	;WinGet, vPID, PID, % "ahk_id " hWnd
	vOutput .= hWnd " " vWinTitle "`r`n"
}
MsgBox, % vOutput
return

;link:
;list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=27824

w:: ;close an AutoHotkey script
DetectHiddenWindows, On
SetTitleMatchMode, 2 ;Contains
vScriptName := "MyScript.ahk"
WinGet, hWnd, ID, % "\" vScriptName " - AutoHotkey v ahk_class AutoHotkey"
WinGet, vPID, PID, % "ahk_id " hWnd
;close
;ID_FILE_EXIT := 65405
PostMessage, 0x111, 65405,,, % "ahk_id " hWnd
;close (alternative)
;WinClose, % "ahk_id " hWnd
;force close
;Process, Close, % vPID
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: How to find reason for crash every few weeks

15 Feb 2018, 15:13

and maybe helps to write to a logfile.

so you could later look at the last actions.
VarunAgw
Posts: 25
Joined: 05 Jan 2016, 11:51
Contact:

Re: How to find reason for crash every few weeks

17 Feb 2018, 20:06

Ravenlord wrote:You can do second script which check for example every 1min if win exist, if not then run script.

Without any code we can only guess why it's crashing. Maybe lost connection to network drive which is required for your script, missing required file, maybe bad var. Who knows :)
It's more than 2000 lines. I don't know what to even share. It happens very rarely so it's very hard to separete the code causing the issue.
VarunAgw
Posts: 25
Joined: 05 Jan 2016, 11:51
Contact:

Re: How to find reason for crash every few weeks

17 Feb 2018, 20:06

SL5 wrote:and maybe helps to write to a logfile.

so you could later look at the last actions.
Is there some automated way to do it?
VarunAgw
Posts: 25
Joined: 05 Jan 2016, 11:51
Contact:

Re: How to find reason for crash every few weeks

17 Feb 2018, 20:09

jeeswg wrote:- In what way is it crashing? Does it show an error message? Does it 'forget' the hotkeys?
- You could set DetectHiddenWindows to On, and use a Loop, with WinWaitActive, and ahk_class AutoHotkey to identify which scripts are open. You could use PostMessage/WinClose to close or Process Close to force close a script.

Code: Select all

q:: ;list AutoHotkey scripts
DetectHiddenWindows, On
WinGet, vWinList, List, ahk_class AutoHotkey
vOutput := ""
Loop, % vWinList
{
	hWnd := vWinList%A_Index%
	WinGetTitle, vWinTitle, % "ahk_id " hWnd
	;WinGetClass, vWinClass, % "ahk_id " hWnd
	;WinGet, vPID, PID, % "ahk_id " hWnd
	vOutput .= hWnd " " vWinTitle "`r`n"
}
MsgBox, % vOutput
return

;link:
;list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=27824

w:: ;close an AutoHotkey script
DetectHiddenWindows, On
SetTitleMatchMode, 2 ;Contains
vScriptName := "MyScript.ahk"
WinGet, hWnd, ID, % "\" vScriptName " - AutoHotkey v ahk_class AutoHotkey"
WinGet, vPID, PID, % "ahk_id " hWnd
;close
;ID_FILE_EXIT := 65405
PostMessage, 0x111, 65405,,, % "ahk_id " hWnd
;close (alternative)
;WinClose, % "ahk_id " hWnd
;force close
;Process, Close, % vPID
return

No! It just terminate itself without any message/warning whatsoever. Does it log crash somewhere?
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: How to find reason for crash every few weeks

17 Feb 2018, 23:08

VarunAgw wrote:
SL5 wrote:and maybe helps to write to a logfile.

so you could later look at the last actions.
Is there some automated way to do it?
https://autohotkey.com/boards/viewtopic ... 22#p202322
Last edited by SL5 on 24 Feb 2018, 03:23, edited 1 time in total.
Ravenlord
Posts: 14
Joined: 19 Jan 2018, 03:43

Re: How to find reason for crash every few weeks

18 Feb 2018, 04:47

VarunAgw wrote:No! It just terminate itself without any message/warning whatsoever. Does it log crash somewhere?
Then it doesn't look like a crash. Imo it look's like error in your code and instead exiting your function, it's exiting a whole script sometimes.

If it's AHK program crash then it should be listed in system event log.
https://www.digitalmastersmag.com/magaz ... windows-8/ Example how to find it, If You don't know.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to find reason for crash every few weeks

19 Feb 2018, 01:35

- How do you know that it's crashing? Does the systray icon disappear? Does it no longer appear in Task Manager.

Taken from:
jeeswg's Explorer tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=31755

To show the Command Line column in Task Manager:
if the Command Line column is not visible in the 'Processes' tab,
go to 'View, Select Columns...' and tick 'Command Line'.
- Some possibilities include: the use of Exit/ExitApp, a script with no hotkeys reaching the end, a Windows update causing a restart, the systray icon being hidden via the Menu command or for some unknown reason.
- You could try running the script in admin mode, maybe another window is closing it, and putting the script in admin mode might protect it. Someone mentioned such a problem once, although it hasn't happened to me personally.
Do Autohotkey scripts require running as administrator? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=41365
- To check that a script is working, you can add FileAppend in various places, and use A_Now or FormatTime to generate a datestamp.
- You could use a variation of my script to periodically list all windows on the system, in case there is a correlation between some window opening and your script closing.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 32 guests