malu05 Posted July 27, 2009 Posted July 27, 2009 I am making a tool to capture the depth buffer in World of Warcraft, and for that i use the screencapture function. I manage to capture 57 bitmaps, then the app crashes with a windows buffer overflow error (buffer for creating BITMAPS). How do i flush the buffer? Do i have to restart GDIplus after each operation or is there another fancy way? expandcollapse popupfor $i = 1 to 100 step + 1 disable() sleep($interval) $hBitmap = _ScreenCapture_Capture('', 0, 0, 1280, 720, False) __ScreenCapture_SaveImage($sFile & "Z-buf"& $i & ".jpg", $hBitmap, False, $iQuality) sleep(10) enable() sleep($interval) $hBitmap = _ScreenCapture_Capture('', 0, 0, 1280, 720, False) __ScreenCapture_SaveImage($sFile & "Difu"& $i & ".jpg", $hBitmap, False, $iQuality) sleep(10) sleep($interval) next ... Func __ScreenCapture_SaveImage($sFileName, $hBitmap, $fFreeBmp, $iQuality) Local $hClone, $sCLSID, $tData, $sExt, $hImage, $pParams, $tParams, $iResult, $iX, $iY If @error Then Return SetError(-1, -1, False) $sExt = StringUpper(_GDIPlus_ExtractFileExt($sFileName)) $sCLSID = _GDIPlus_EncodersGetCLSID($sExt) If $sCLSID = "" Then Return SetError(-2, -2, False) $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) If @error Then Return SetError(-3, -3, False) Switch $sExt Case "BMP" $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $giBMPFormat) _GDIPlus_ImageDispose($hImage) $hImage = $hClone Case "JPG", "JPEG" $tParams = _GDIPlus_ParamInit(1) $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tData)) Case "TIF", "TIFF" $tParams = _GDIPlus_ParamInit(2) $tData = DllStructCreate("int ColorDepth;int Compression") DllStructSetData($tData, "ColorDepth", $giTIFColorDepth) DllStructSetData($tData, "Compression", $giTIFCompression) _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOLORDEPTH, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "ColorDepth")) _GDIPlus_ParamAdd($tParams, $GDIP_EPGCOMPRESSION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Compression")) EndSwitch If IsDllStruct($tParams) Then $pParams = DllStructGetPtr($tParams) $iResult = _GDIPlus_ImageSaveToFileEx($hImage, $sFileName, $sCLSID, $pParams) _GDIPlus_ImageDispose($hImage) If $fFreeBmp Then _WinAPI_DeleteObject($hBitmap) Return SetError($iResult = False, 0, $iResult = True) EndFunc ;==>_ScreenCapture_SaveImage [center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]
Authenticity Posted July 27, 2009 Posted July 27, 2009 If you don't need the $hBitmap returned by the _ScreenCapture_Capture() function then release it or specify true in the third parameter of the __ScreenCapture_SaveImage() function. Not sure if this is the cause of the buffer overflow error.
malu05 Posted July 27, 2009 Author Posted July 27, 2009 If you don't need the $hBitmap returned by the _ScreenCapture_Capture() function then release it or specify true in the third parameter of the __ScreenCapture_SaveImage() function. Not sure if this is the cause of the buffer overflow error.Ahh yea, that did it.There error was caused by _WinAPI_CreateCompatibleBitmap, apparently because _WinAPI_ReleaseDC was not used. [center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now