SHARE
TWEET

gdip_CloneBitmapArea memory leak

twiz Mar 10th, 2020 534 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;   *   GDI+ Library:
  2. ;   https://raw.githubusercontent.com/Masonjar13/AHK-Library/blob/master/Required-Libraries/Gdip_All.ahk
  3.  
  4. ;   *   GDI+ ImageSearch:
  5. ;   https://raw.githubusercontent.com/MasterFocus/AutoHotkey/master/Functions/Gdip_ImageSearch/Gdip_ImageSearch.ahk
  6.  
  7.  
  8. #SingleInstance, Force
  9. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  10. ; #Warn  ; Enable warnings to assist with detecting common errors.
  11. SendMode, Input  ; Recommended for new scripts due to its superior speed and reliability.
  12. SetWorkingDir, %A_ScriptDir%  ; Ensures a consistent starting directory.
  13. DetectHiddenWindows, On
  14. OnExit("ExitFunct")
  15.  
  16. pToken := Gdip_Startup()
  17. SetTimer, Monitor, 100
  18. Return
  19.  
  20. F12::ExitApp    ; Just in case...
  21.  
  22. Monitor:
  23.     ;   Get the HWND of the current active window
  24.     WinGet, _HWND, ID, A
  25.     ;   Get image from current active window
  26.     pBitmap     := Gdip_BitmapFromHWND(_HWND)
  27.  
  28.  
  29.     ;   Copy specific section
  30.     pBitmapChat := Gdip_CloneBitmapArea(pBitmap, 0, 0, 100, 100)
  31.     ;   *****   THIS LINE CAUSES THE MEMORY "LEAK"  *****
  32.  
  33.  
  34.     ;   Delete the big full-window image to free memory
  35.     Gdip_DisposeImage(pBitmap)
  36.     ;   Search to see if current section matches old section
  37.     Gdip_ImageSearch(pBitmapOld, pBitmapChat, ImgComp)
  38.    
  39.     ;   If there was *NO* match (i.e. new window/diff information)...
  40.     If !ImgComp {
  41.         ;   Copy current section as old section
  42.         pBitmapOld := pBitmapChat
  43.         ;   Play alert sound/do something to notify
  44.         SoundPlay, *16
  45.     }
  46.  
  47.    
  48.     ;   Uncommenting this line breaks the functionality, never get a match and 'spams' alert sound
  49.     ;Gdip_DisposeImage(pBitmapChat)
  50.    
  51.     ;   VarSetCapacity does not work
  52.     ;VarSetCapacity(pBitmapChat, 0)
  53. Return
  54.  
  55. ExitFunct(){
  56.     Gdip_DisposeImage(pBitmap)
  57.     Gdip_DisposeImage(pBitmapOld)
  58.     Gdip_DisposeImage(pBitmapChat)
  59.     Gdip_Shutdown(pToken)
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top