Opened 17 years ago
Closed 16 years ago
#1040 closed Bug (Fixed)
_ScreenCapture_Capture(): GDI object leak with cursor capture
| Reported by: | rover | Owned by: | J-Paul Mesnage |
|---|---|---|---|
| Milestone: | 3.3.7.0 | Component: | Standard UDFs |
| Version: | 3.3.0.0 | Severity: | None |
| Keywords: | _ScreenCapture_Capture | Cc: |
Description
The returned bitmap handles from _WinAPI_GetIconInfo() are not deleted.
(only $aIcon[4] bitmask has a valid handle when used with cursor)
modified _ScreenCapture_Capture() with added error handling in attached file
Environment = 3.3.0.0 under WIN_XP/Service Pack 2 X86
#include <ScreenCapture.au3>
Global $hBitmap, $hProcess, $aGDIObjs
$hProcess = _WinAPI_GetCurrentProcess()
If @error Then $hProcess = 0xFFFFFFFF
While 1
Sleep(50)
$hBitmap = _ScreenCapture_Capture("", 0, 0, 400, 300, True)
_WinAPI_DeleteObject($hBitmap)
$aGDIObjs = DllCall("user32.dll", "int", "GetGuiResources", "hwnd", $hProcess, "int", 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : GDI Objects = ' & $aGDIObjs[0] & @CRLF)
If $aGDIObjs[0] > 40 Then Exit
WEnd
Attachments (1)
Change History (7)
by , 17 years ago
| Attachment: | _ScreenCapture_Capture.au3 added |
|---|
comment:1 by , 17 years ago
| Milestone: | → 3.3.1.2 |
|---|---|
| Owner: | changed from to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed in version: 3.3.1.2
comment:3 by , 16 years ago
| Resolution: | Fixed |
|---|---|
| Status: | closed → reopened |
comment:5 by , 16 years ago
I'm pretty sure the problem here is that _WinAPI_GetIconInfo returns TWO bitmaps and we are only deleting ONE of them. The cursor section of the function needs to check if $aIcon[5] is valid bitmap and delete if it is. Depending on what cursor is being displayed $aIcon[5] may not alway be a valid bitmap. From the tests I've done, when the cursor is an I-beam, the bitmap will NOT be valid. Almost all other ones were valid.
If $fCursor Then Local $aCursor = _WinAPI_GetCursorInfo() If $aCursor[1] Then Local $hIcon = _WinAPI_CopyIcon($aCursor[2]) Local $aIcon = _WinAPI_GetIconInfo($hIcon) _WinAPI_DeleteObject($aIcon[4]); delete bitmap mask return by _WinAPI_GetIconInfo() ---->>>>>>>>>>>>If $aIcon[5] <> 0 Then _WinAPI_DeleteObject($aIcon[5]); delete bitmap hbmColor return by _WinAPI_GetIconInfo() _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon) _WinAPI_DestroyIcon($hIcon) EndIf EndIf
comment:6 by , 16 years ago
| Milestone: | → 3.3.7.0 |
|---|---|
| Resolution: | → Fixed |
| Status: | reopened → closed |
Fixed by revision [5768] in version: 3.3.7.0

_ScreenCapture_Capture() UDF with added error handling