This is leaking memory, but i dont know how to fix it. Any help? I am scanning pixel x539 y182 of a window every 150-300ms for its color, and RAM just goes up every second in my ahk script until 2gb and my pc crashes
Code: Select all
#NoEnv
#include Gdip_All.ahk ;https://www.autohotkey.com/board/topic/29449-gdi-standard-library-145-by-tic/
SendMode Input
SetWorkingDir %A_ScriptDir%
global AhkColorPos := [539, 182]
global hwnd
OnExit("CloseGdip")
if (!Token := Gdip_Startup())
{
MsgBox, 48, Error!, Gdiplus failed to start. Please ensure you have Gdiplus on your system
ExitApp
}
if (!hwnd := WinExist("RuneLite"))
{
MsgBox, 48, Error!, RuneLite not running!
ExitApp
}
Random r, 150, 300
SetTimer, MainLoop, %r%
MainLoop()
{
CoordMode Mouse, Window
switch GetAhkColorState()
{
}
}
return
F1::Pause
return
F12::Reload
return
GetAhkColorState()
{
Bitmap := Gdip_BitmapFromHWND(hwnd)
Color := Gdip_GetPixel(Bitmap, AhkColorPos[1], AhkColorPos[2]) & 0xFFFFFF
SetFormat, integer, hex
Color +=0
return %Color%
}
CloseGdip()
{
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
}