Strange memory r/w error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Strange memory r/w error

Post by braunbaer » 20 Jan 2022, 19:31

Hi,

I have a script file about 2000 lines big + several include files. It basically works, but sporadically I get a strange error message when a specific controlget is executed. The error always occurs at exactly the same place (but most of the time, there is no error when executing these lines):

Code: Select all

---------------------------
saff.ahk
---------------------------
Critical Error in #include file "c:\bat\Help.ahk":
     Invalid memory read/write.

	Line#
	183: Sleep,200
	184: }
	186: {
	187: ControlGetFocus,cntrl,A
	188: debug("#NoFocus", "Focused control: " cntrl)  
	190: if (cntrl) && (cntrl<>"TPSSynEdit1")  
	190: {
--->	191: ControlGet,Result,Selected,,%cntrl%,A
	192: t := "CtrlGet"
	193: }
	195: Else
	195: {
	196: clpSaveAndSet()  
	197: Send,^c
	198: Result := clpGetAndRestore()

The program is now unstable and will exit.
---------------------------
OK   
---------------------------
The control in question is a firefox page. Most of the time everything works fine, but sporadically I get this error message.

i have no idea how to debug this, I have checked that according to my debugging output (line 188), the variable cntrl contains the correct data.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Strange memory r/w error

Post by iseahound » 20 Jan 2022, 21:04

Your best bet with memory critical errors is to remove the offending section and hope the error doesn't reappear. The reason is that the line that AutoHotkey assumes to be the memory violation very likely not the true cause of the memory violation, it's just the line that causes the error. As you find more symptoms, just remove all of them, until you finally reach the origin of the error.

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

Re: Strange memory r/w error

Post by swagfag » 21 Jan 2022, 13:20

u have a huge ass script and no idea where to start looking. i think ur best bet is downloading visual studio, recompiling ahk with address sanitizer enabled and debug ur script with the release build under visual studio. then if ure lucky u might get a clue as to what could be corrupting the memory

https://docs.microsoft.com/en-us/cpp/build/how-to-debug-a-release-build

braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Strange memory r/w error

Post by braunbaer » 27 Jan 2022, 18:17

iseahound wrote:
20 Jan 2022, 21:04
Your best bet with memory critical errors is to remove the offending section and hope the error doesn't reappear.
Well, thank you for the hint...
I have removed that statement, which is not crucial for the script to run (I just send ctrl-c instead of using controlget to get the marked text, I have done this before only for the control TPSSynEdit1 where controlget does not work), and now, the script runs without any error. There are a lot of other controlget statement at other places in the script, only this one caused problems.
I'd have preferred to use controlget instead of copying to the clipboard, but I don't want to spend maybe weeks for debugging this issue...

Post Reply

Return to “Ask for Help (v1)”