Sign in to follow this  
Followers 0
jimmer

Recursion level has been exceeded from Binary Decompression.

4 posts in this topic

#1 ·  Posted (edited)

Basically I need my script detecting images running upwards of days. After about 5 hours I encounter a recursion error.

"Func _WinAPI_Base64Decode($sB64String)

Error: Recursion level has been exceeded - Autoit will quit to prevent stack overflow."

Is there any way for me to decompress the binary file once and then recall the decompressed image rather than infinitely decompressing it each time it recalls the image to search?

#include <ImageSearch.au3>
#include <GDIPlus.au3>
HotKeySet("{ESC}", "exiting")
Local $x = 0, $y = 0


_GDIPlus_Startup()


While 1


$hBitmapA = _GDIPlus_BitmapCreateFromMemory(_faceb(), True)
$result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0)
If $result > 0 Then
MouseMove($x,$y)
ToolTip("One", 800, 600)
EndIf


Sleep(200)


$hBitmapB = _GDIPlus_BitmapCreateFromMemory(_chrome(), True)
$result = _ImageSearch($hBitmapB, 1, $x, $y, 20, 0)
If $result > 0 Then
MouseMove($x,$y)
ToolTip("Two", 800, 600)
EndIf


Sleep(200)


WEnd


_GDIPlus_Shutdown()


Func _chrome($bSaveBinary = False, $sSavePath = @ScriptDir)
Local $chrome
$chrome &= 'iVBORw0KGgoAAAANSUhEUgAAABEAAAAQCAIAAAB/UwMIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAACzSURBVDhPvZC9EcIwDIW1CTNAxSysxAw0TMBG0vMCpOAoqNCPLeMkx0EBL3LkT9FT4lApBbq6AIyVAK160mUe3dz3uwi3dHRCorUCpFVVVgEZcfbURBDVrCodxa5Emycgc0CmJp8woqCCok80j4vbzTdLvZQp+ranQ4TumWVzvEVE03SmiDCqR3skPWzM6TFg7h6TROrvCXzr4ZquTZ9g9Xyl9W97XChiFf/sqWf81T9gfgKgUW6JxR8GSgAAAABJRU5ErkJggg=='
Local $bString = Binary(_WinAPI_Base64Decode($chrome))
If $bSaveBinary Then
Local $hFile = FileOpen($sSavePath & "\chromess.png", 18)
FileWrite($hFile, $bString)
FileClose($hFile)
EndIf
Return  $bString
EndFunc   ;==>_chrome


Func _faceb($bSaveBinary = False, $sSavePath = @ScriptDir)
Local $faceb
$faceb &= 'iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAIAAAD9MqGbAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAAEFSURBVDhP1Y+tbgJBFIXnuVCIFVVIUrMVdZAQnoAVPAKiAiQoROENcC0KjaHzs6IC0SCAtJCUc+eQZViy2dQ04ezZuXfvPV8mq1Lnlfoqx1UTfGQnW6eclWItipVemmtxxZbFC6RQeJ/aL5Vat9SI+RucskZQHFE8eHgelhoxT1gh0Rljcwm63hq/LdzP4fi12S9Xaw55kzKA8BiTpUPP5h+/gTgUwhghIV1AbnffANrJiD/JIQGQGhiUpUPzqijuh0MAeJT2FQ53MJlQ6eeGKyCAhKQyhj7HA41e37livpDkj5FhX33sccV8IUmTzA2Zv1eykUxyCfiWbHamzF/Iv+r/Sa1PdbnrG64bX5YAAAAASUVORK5CYII='
Local $bString = Binary(_WinAPI_Base64Decode($faceb))
If $bSaveBinary Then
Local $hFile = FileOpen($sSavePath & "\facebook.png", 18)
FileWrite($hFile, $bString)
FileClose($hFile)
EndIf
Return  $bString
EndFunc   ;==>_faceb


Func _WinAPI_Base64Decode($sB64String)
Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
$aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
Return DllStructGetData($bBuffer, 1)
EndFunc   ;==>_WinAPI_Base64Decode


Func Exiting()
Exit
EndFunc
Edited by jimmer

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This isn't a recursion problem! Your code produces a memory leak because you load everytime the bitmap in GDI format without releasing it! Either you release it in the loop or you move the _GDIPlus_BitmapCreateFromMemory() functions outside the main loop and release it when closing the script.

Br,

UEZ

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

UEZ, I just want to say thank you for all your contributions on the forum. I used your binary converter for this  :bye:

Okay, back to the topic,

$hBitmapA = _GDIPlus_BitmapCreateFromMemory(_faceb(), True)
$hBitmapB = _GDIPlus_BitmapCreateFromMemory(_chrome(), True)

While 1

$result = _ImageSearch($hBitmapA, 1, $x, $y, 20, 0)
If $result > 0 Then
MouseMove($x,$y)
ToolTip("One", 800, 600)
EndIf

Sleep(200)

$result = _ImageSearch($hBitmapB, 1, $x, $y, 20, 0)
If $result > 0 Then
MouseMove($x,$y)
ToolTip("Two", 800, 600)
EndIf

Sleep(200)

WEnd

I have tried putting them on the outside. But once the BitmapCreateFromMemory is no longer part of the loop, it no longer searches for the results the second time around.

I found that binary or regular images did not matter, as long as the image were loaded outside the loop, it would not have any recursion errors.

I am thinking BitmapCreateFromMemory must be stored inside the loop. But is there is any way to decompress it before the loop?

I will try keeping BitMapCreateFromMemory inside the loop and _WinAPI_DeleteObject in the loop as well. Will;

_WinAPI_DeleteObject($hBitmapA)
_WinAPI_DeleteObject($hBitmapB)

be enough to release it inside the loop?

Edited by jimmer

Share this post


Link to post
Share on other sites

Yes using _WinAPI_DeleteObject() will release the GDI (not GDIPlus!) bitmap handle but for me it makes no sense to have the _GDIPlus_BitmapCreateFromMemory() inside the loop to create the same bitmap on each loop passing.

I never used _ImageSearch()...

 

Br,

UEZ

1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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
Sign in to follow this  
Followers 0