Authotkey and Threading

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
Mradr
Posts: 1
Joined: 30 Dec 2020, 18:37

Authotkey and Threading

Post by Mradr » 30 Dec 2020, 18:50

image.png
image.png (10.88 KiB) Viewed 2418 times
Hello, not sure what is really causing the issue, so was hoping someone could point me in the right direction. I have written my code to hopefully to make use of m-threads, but I seem to be getting an issue about (having searching the error up) with data being share and thus causing the error you see in image. From as I know ~ I am not sharing anything and it should be creating thread. I am using AHK1_h at this time.

If there is any other information you need, please feel free to ask.

thread.ahk

Code: Select all

#Persistent
#NoTrayIcon
#include, Gdip.ahk
#include, Vis2.ahk

SetBatchlines, -1
SetWorkingDir %A_ScriptDir%
CoordMode,Mouse,Window
CoordMode,Pixel,Window
pToken := Gdip_Startup()

stats := CriticalObject(A_Args[1])
SetTimer, update_stats, 250

update_stats:
    if (!stats["user_pause"]) {
        try {
            start:=A_TickCount
            WinGet, hwnd, ID, A
            ;pToken := Gdip_Startup()
            bmpHaystack := Gdip_BitmapFromScreen( "hwnd:" hwnd )

            stats["value1"] := OCR( bmpHaystack, , [100, 23, 50, 25] ) + 0
            if !stats["value1"] {
                stats["value1"] := .7
            }

            stats["value2"] := OCR( bmpHaystack, , [100, 42, 50, 25] ) + 0
            if !stats["value2"] {
                stats["value2"] := 90
            }

            difference:=A_TickCount-start
            ;gdip_Shutdown( pToken )
            Gdip_DisposeImage(bmpHaystack)
            ;MsgBox, %difference%
        }
    }
    SetTimer, update_stats, 250
    return

Code: Select all

global stats := CriticalObject( {"value1":.7, "value2":90, "user_pause":1} )
global get_stats_thread := AhkThread( "GetStats.ahk", &stats "", true )
In the main thread ~ I also have it searching for images as well whenever a key is press. I know in the past I had issue with pToken := Gdip_Startup() and ;gdip_Shutdown( pToken ) that would crash the program with no error. While here I am just trying to play around with that - I wonder if that is what is going on still. Is Gdip M-thread safe? Are there any workarounds? I see a lot of random threads here looks like it should work M-threaded, but I am not sure at this point.

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Authotkey and Threading

Post by HotKeyIt » 31 Dec 2020, 09:19

AFAIK there was a non critical issue with GDIP library, try using #WarnContinuableException, Off in GetStats.ahk

Post Reply

Return to “AutoHotkey_H”