AHK crashes without error. How to find the causing part of the script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Spitzi
Posts: 313
Joined: 24 Feb 2022, 03:45

AHK crashes without error. How to find the causing part of the script?

Post by Spitzi » 12 Jan 2023, 16:01

Hi there.

I have a fairly extensive script (8000+ lines). The script interacts with other programs, uses a few timers to run functions e.g. when programs are active. Also, using COM, i read and write in an open word document, using a few different functions. I also regulalrly access ini-files to retrieve and write values.

A while ago, I noticed that sometimes the script crashes and quits without an error. So far, I have no idea why. I'm using SciTE to debug. Sometimes everything works finde for a few minutes, before the crash happens. There's nothing on the debug console.

Can anyone give me a hint what might cause the problem or how I could figure out what's wrong? What possible causes could crash AHK?

Thanks in advance.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: AHK crashes without error. How to find the causing part of the script?

Post by mikeyww » 12 Jan 2023, 16:57

The only case I have seen where AHK terminates without error, aside from an Exit, ExitApp, or non-persistent script, is when antivirus or another program terminates it. You can easily use the script to log events to a file, to see where it stops. I'm not sure how you define "crashes and quits without an error", because "crash" suggests that an error of some kind became apparent to you. On the other hand, if no such thing happened, then the program might have quit without a crash. Believe it or not, some other posts have described this sort of problem when the answer was that the script executed an ExitApp command.

User avatar
lmstearn
Posts: 694
Joined: 11 Aug 2016, 02:32
Contact:

Re: AHK crashes without error. How to find the causing part of the script?

Post by lmstearn » 13 Jan 2023, 00:00

If you don't expect a script to terminate, and it terminates, it's most likely to be some kind of error in the script which caused it to crash.
Crashes should be detected by WER, there's a bit on how to use it here. :)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

Spitzi
Posts: 313
Joined: 24 Feb 2022, 03:45

Re: AHK crashes without error. How to find the causing part of the script?

Post by Spitzi » 13 Jan 2023, 00:34

Thanks mikeyww

I'll check the exitapps...

But i get a "Ahk does not react anymore..." Message on the screen, like sometimes programs do when they freeze.

I should say that i have about 6 users using the script at the same time and sharing data (using ini files) over a network drive. When they run the script, they sometimes also have the effect of ahk freezing and quitting.

It usually happens -or is somewhat reproducible - when the script performs changes in a word document.

So I guess the questions are:
- is there a known issue where ahk freezes?
- if it is a virus scanner that causes the problem, what are skript actions that trigger it?

Unfortunately I do not have control over the virus scanner, nor am i administrator when the script runs...

Thanks!!

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: AHK crashes without error. How to find the causing part of the script?

Post by mikeyww » 13 Jan 2023, 06:39

1. You could test in a one-user setting, to see if the problem still occurs.
2. If the problem does occur, you can experiment with changes to the script, to see if certain commands are associated with the problem.
3. You can test the script on your own computer, where you can control other programs if needed.

If you do all three of these things, you will make progress and narrow down the possibilities.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK crashes without error. How to find the causing part of the script?

Post by swagfag » 13 Jan 2023, 11:42

since u have basically absolutely no clue whatsoever what might be causing the "crashes"(if theyre even that), and ure not an administrator, ur best bet is recompiling ahk to log every line executed and observe roughly where the script stops working
eg u can insert some print to file logic (Line::ToText(....)) around here https://github.com/AutoHotkey/AutoHotkey/blob/8f8332238f92722a1c0c4c05bcf586993be375af/source/script.cpp#L11849

but if some other program is killing ur script, eg the antivirus, due to ur tripping some of its heuristics, then this information may or may not be completely useless. usually, if that were the case, ud run gflags and see what killed it, but since ure not an administrator...
https://bugslasher.net/2011/04/17/who-the-hell-killed-my-process/
https://techcommunity.microsoft.com/t5/ask-the-performance-team/what-killed-my-process/ba-p/375329

User avatar
lmstearn
Posts: 694
Joined: 11 Aug 2016, 02:32
Contact:

Re: AHK crashes without error. How to find the causing part of the script?

Post by lmstearn » 13 Jan 2023, 22:57

Yep, the "ceased to interact with Windows" message usually means there's a CPU devouring loop gone off the rails, if you don't get that, check the event logs to see if AHK actually crashes.
And if the users are not running compiled scripts, check their AHK versions are the same as yours, just in case.
Does the script use Clipboard commands when editing Word? Using code found here might be a workaround for possible issues.
@swagfag: Any of the C++ snippets here any good for it? (if it's in a loop, the file open & close might slow things down- in that case save everything to string with line feeds and use this).
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK crashes without error. How to find the causing part of the script?

Post by swagfag » 14 Jan 2023, 05:11

yes, opening and closing a file handle and writing to disk on every loop iteration will definitely slow things down, but thats not important. what's important is to log each line as soon as its executed before the script has had a chance to crash(or another program to kill it)

Spitzi
Posts: 313
Joined: 24 Feb 2022, 03:45

Re: AHK crashes without error. How to find the causing part of the script?

Post by Spitzi » 28 Jan 2023, 06:44

Hi guys. You are marvellous! Many good hints in your posts, thank you so much.

I used the OutDebug command together with Scite to narrow down the problem. The crash occurred everytime I was using ImageSearch with different images in quick succession. At the same time I had a function being called with every MouseMove-Event, that showed an image in a gui on screen. I changed my code so that the image is shown just when it is needed and not after every MouseMove Event. After that, I had no crash anymore.

So I conclude it must have been something to do with my code accessing image-files in rapid succession. Maybe this is a known issue?

Anyway, again, this forum has made my day. Thanks for your help, everybody. Really appreciated.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK crashes without error. How to find the causing part of the script?

Post by swagfag » 26 Feb 2023, 15:57

Spitzi wrote:Maybe this is a known issue?
no, its not a known issue nor has anybody confirmed its an issue to begin with. its actually highly improbable that uve actually fixed anything
swagfag wrote: but if some other program is killing ur script, eg the antivirus, due to ur tripping some of its heuristics
heuristics(known only to the antivirus vendor) such as opening a lot of file handles over a specified(known only to the antivirus vendor) period of time. seems like the most plausible explanation

Spitzi
Posts: 313
Joined: 24 Feb 2022, 03:45

Re: AHK crashes without error. How to find the causing part of the script?

Post by Spitzi » 27 Feb 2023, 07:16

Thank you @swagfag.

Yeah, I see now how antivirus software could cause that problem. Thanks for pointing that out.

Post Reply

Return to “Ask for Help (v1)”