Jump to content

Memory Leak in ScreenCapture


damael
 Share

Recommended Posts

Hi

First sorry for my bad english.

I always get this error when i run my script over a longer time.

_winapi_createCompatibleBitmap: Not enough storage to process the command

The only place where this command is executed is in _ScreenCapture_Capture. I am doing a OCR with OhSeeAre.exe and for this i must do the screencapture.

I already tried to correct the _ScreenCapture_Capture with the following but, the error still happens. It comes after 30 minutes to one and a half hour.

Func _ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)
    Local $iH, $iW, $hWnd, $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon

    If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CXSCREEN)
    If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics($__SCREENCAPTURECONSTANT_SM_CYSCREEN)
    If $iRight < $iLeft Then Return SetError(-1, 0, 0)
    If $iBottom < $iTop Then Return SetError(-2, 0, 0)

    $iW = $iRight - $iLeft
    $iH = $iBottom - $iTop
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
    _WinAPI_SelectObject($hCDC, $hBMP)
    _WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, $__SCREENCAPTURECONSTANT_SRCCOPY)

    If $fCursor Then
        $aCursor = _WinAPI_GetCursorInfo()
        If $aCursor[1] Then
            $hIcon = _WinAPI_CopyIcon($aCursor[2])
            $aIcon = _WinAPI_GetIconInfo($hIcon)
            _WinAPI_DrawIcon($hCDC, $aCursor[3] - $aIcon[2] - $iLeft, $aCursor[4] - $aIcon[3] - $iTop, $hIcon)
            _WinAPI_DestroyIcon($hIcon)
            _WinAPI_DeleteObject($aIcon[4]); <- THIS!
            _WinAPI_DeleteObject($aIcon[5]); <- THIS!
        _WinAPI_DeleteObject($aIcon)
        EndIf
    EndIf

    _WinAPI_ReleaseDC($hWnd, $hDDC)
    _WinAPI_DeleteDC($hCDC)
    If $sFileName = "" Then Return $hBMP

    _ScreenCapture_SaveImage($sFileName, $hBMP)
    _WinAPI_DeleteObject($hBMP)
EndFunc ;==>_ScreenCapture_Capture

From http://www.autoitscript.com/forum/index.php?showtopic=97843 and http://www.autoitscript.com/forum/index.php?showtopic=89542&st=40

I am testing a loop where it only does screencapture. It run for 30 minutes from the old code then came the error. Right now i am testing the new code... Lets see what happens

Please help, this bug is really annoying.

Thx :)

bb

Link to comment
Share on other sites

It ran for more than a half an hour now and the error didn't happen... I leave it running. That is what i don't understand. I did test it yesterday and the error also didn't happen, but when i execute the hole script it does happen always after one hour -.-

The only place where this _winapi_createcompatiblebitmap is executed is in the screencapture.

Does anyone have an idea?

Link to comment
Share on other sites

After 15 Minutes Error: _WinAPI_CreateCompatibleBitmap: Not enough storage is available to process this command.

Is the error not from screencapture?

Is this not fixed at the time?

What to do then is there an alternative to screencapture that does the same without the error?

pls help

Link to comment
Share on other sites

Calm down, young grasshopper. To learn, you must be patient. One person can not know everything, sometimes you must wait for someone else to answer your questions.

The Trac issue has a nice example that displays how many GDI objects you currently have. Why not try it with your code and determine if you have a memory leak for yourself?

Link to comment
Share on other sites

Hi,

this could have something to do with a  leak problem i had with _GDIPlus_BitmapLockBits() which is used by the screencapture-Functions.

The solution was changing

DllCall($ghGDIPDll, "int", "GdipBitmapUnlockBits", "hwnd", $hBitmap, "int*", DllStructGetPtr($tBitmapData))
to
DllCall($ghGDIPDll, "int", "GdipBitmapUnlockBits", "hwnd", $hBitmap, "ptr", DllStructGetPtr($tBitmapData))
in the screencapture.au3

Andy

Link to comment
Share on other sites

sorry, my fault....

change the mentioned line above in the GDIplus.au3 to

Func _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData)
    Local $aResult

    $aResult = DllCall($ghGDIPDll, "int", "GdipBitmapUnlockBits", "hwnd", $hBitmap, "ptr", DllStructGetPtr($tBitmapData))
    If @error Then Return SetError(@error, @extended, False)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_BitmapUnlockBits
Link to comment
Share on other sites

Ok i tested it after 45 Minutes came the error. GDI Objects = 39

I read somewhere that the problem is createCompatibleBitmap itself and instead there should be used createDIBSection. Because the createCompatibleBitmap saves to a storage which is limited, like a root partition. But i dont know where i read this.

Is there any alternative to _screencapture_capture? Or is there a screencapture that does use the createDIBSection?

Edited by damael
Link to comment
Share on other sites

Link to comment
Share on other sites

  • 10 years later...
On 11/12/2009 at 2:39 AM, Yashied said:

What are you talking about? There written black on white (yellow):

 

 

And

 

 

Just use the AutoIt 3.3.1.2 and above.

No.

3.3.14.5

Don't work/ Memory leaks on _ScreenCapture_Capture()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...