Page 2 of 3
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 4:33 am
by andyglezl
Ya vieron este post ?
Quizá hubo algún cambio significativo despues de esta version...
viewtopic.php?f=35&t=4381
koke wrote:Hola Luis
con la nueva versión de de hmg 3.4.1 se soluciono el problema de memoria, ya hace un rato que lo descargue y hasta el momento se han acabado todos los problemas referentes a la memoria.
Saludos.
De esta otra forma, también hace lo mismo...
Code: Select all
#include "hmg.ch"
*------------------------------------------------------------------------------*
Function Main()
*------------------------------------------------------------------------------*
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT 400 ;
TITLE '' //;
// MAIN
define button test
row 10
col 10
caption 'test'
action test()
end button
END WINDOW
ACTIVATE WINDOW Win_1
Return
*-----------------------------------------------------------------------------------*
procedure test
*-----------------------------------------------------------------------------------*
local i, hDesktop, nDesktopWidth, nDesktopHeight
for i := 1 to 1000
cFileName := strzero(i,4)+".jpg"
hBitmap := BT_BitmapCaptureDesktop( )
BT_BitmapSaveFile( hBitmap, cFileName, BT_FILEFORMAT_JPG )
BT_BitmapRelease( hBitmap )
next i
msginfo('fin')
return
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 7:19 pm
by srvet_claudio
Hi
Roberto,
try with this code, work fine for me in Win XP 32 bit.
I added the functions:
RELEASE MEMORY
DO EVENTS
hb_releaseCPU()
Code: Select all
#include "hmg.ch"
*------------------------------------------------------------------------------*
Function Main()
*------------------------------------------------------------------------------*
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 400 ;
HEIGHT NIL ;
TITLE '' ;
MAIN
define button test
row 10
col 10
caption 'test'
action test()
end button
@ 50, 10 LABEL Label_1 AUTOSIZE
END WINDOW
ACTIVATE WINDOW Win_1
Return
*-----------------------------------------------------------------------------------*
procedure test
*-----------------------------------------------------------------------------------*
local i, hDesktop, nDesktopWidth, nDesktopHeight
hDesktop := BT_SCR_GETDESKTOPHANDLE()
nDesktopWidth := GetDesktopWidth()
nDesktopHeight := GetDesktopHeight()
y := 90
for i := 1 to 1000
Win_1.Label_1.VALUE := { i, ") ", HMG_GetObjectCount()[1], HMG_GetObjectCount()[2], HMG_GetObjectCount()[3], " --- ", GetProcessMemoryInfo()[3]/1024/1024 }
xSaveWindowByHandle ( hDesktop , strzero(i,4) + '.' + 'jpg' , 0 , 0 , nDesktopWidth , nDesktopHeight )
IF i % 50 == 0
RELEASE MEMORY // ADD
cName := "Label_"+hb_ntos(i)
@ y, 10 LABEL &cName OF Win_1 AUTOSIZE
y = y + 30
xValue := { i, ") ", HMG_GetObjectCount()[1], HMG_GetObjectCount()[2], HMG_GetObjectCount()[3], " --- ", GetProcessMemoryInfo()[3]/1024/1024 }
SetProperty( "Win_1", cName, "VALUE", xValue )
ENDIF
DO EVENTS // ADD
hb_releaseCPU() // ADD
next i
msginfo('fin')
return
*-----------------------------------------------------------------------------------*
FUNCTION xSaveWindowByHandle ( nHandle , cFileName , nRow , nCol , nWidth , nHeight )
*-----------------------------------------------------------------------------------*
LOCAL hBitmap
hBitmap := xBT_BitmapCaptureClientArea ( nHandle , nRow, nCol, nWidth, nHeight)
IF hBitmap <> 0
IF UPPER(RIGHT( cFileName , 4 ) ) == '.GIF'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_GIF )
ELSEIF UPPER(RIGHT( cFileName , 4 ) ) == '.JPG'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_JPG )
ELSEIF UPPER(RIGHT( cFileName , 4 ) ) == '.PNG'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_PNG )
ELSEIF UPPER(RIGHT( cFileName , 4 ) ) == '.BMP'
BT_BitmapSaveFile (hBitmap, cFileName , BT_FILEFORMAT_BMP )
ENDIF
BT_BitmapRelease (hBitmap)
ENDIF
RETURN hBitmap
Function xBT_BitmapCaptureClientArea ( nHandle , Row, Col, Width, Height)
LOCAL New_hBitmap
LOCAL Max_Width := BT_ClientAreaWidth( nHandle )
LOCAL Max_Height := BT_ClientAreaHeight( nHandle )
bt_FillRectIsNIL (@Row, @Col, @Width, @Height, 0, 0, Max_Width, Max_Height)
bt_AdjustWidthHeightRect (Row, Col, @Width, @Height, Max_Width, Max_Height)
New_hBitmap := BT_BMP_CAPTURESCR ( nHandle , Col, Row, Width, Height, BT_BITMAP_CAPTURE_CLIENTAREA)
Return New_hBitmap
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 8:08 pm
by Roberto Lopez
srvet_claudio wrote:Hi Roberto,
try with this code, work fine for me in Win XP 32 bit.
I added the functions:
RELEASE MEMORY
DO EVENTS
hb_releaseCPU()
Sadly, the problem remains here (Windows 7 Pro 32 bits).
The program generates 467 images, being the last a black one.
I'm attaching the first image and the 466th.
I've changed the main window in the demo to topmost and shred the desktop between it and the task manager showing system memory usage.
Capture #1:
- 0001.jpg (194.56 KiB) Viewed 3962 times
Capture #466:
- 0466.jpg (205.4 KiB) Viewed 3962 times
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 9:05 pm
by KDJ
Dear
Dr. Claudio Soto
I tested it in Win-XP, machine 1.5 GB memory.
Results:
- memory usage on program start: 4 MB,
- maximum memory usage during execution:
1200 MB,
- count of created files: 331,
- files from 1 to 330: good,
- file 331: bad (blank).
This problem is similar to that reported by
mol here:
viewtopic.php?f=43&t=4738&start=70#p46200
and I confirmed here:
viewtopic.php?f=43&t=4738&start=70#p46338
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 10:06 pm
by srvet_claudio
It is a very strange problem because it works fine for me in Win 10 (64-bit) and in Win XP (32 bit), with add:
RELEASE MEMORY
DO EVENTS
hb_releaseCPU()
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 10:37 pm
by Roberto Lopez
srvet_claudio wrote:It is a very strange problem because it works fine for me in Win 10 (64-bit) and in Win XP (32 bit), with add:
RELEASE MEMORY
DO EVENTS
hb_releaseCPU()
As I've already mentioned, I've attempted to use SaveWindowByHandle() function, present in older versions of HMG, with the same results (the app crash after certain number of generated files).
And.. I've just fixed!
SaveWindowByHandle used a bitmap that was not released.
I've simply added:
At the function end, and all works smoothly now.
Maybe the same problem in Bos Taurus (some bitmap not released)?... perhaps some temporary one intermediate work?
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 10:40 pm
by Roberto Lopez
And... regarding Windows 10... could be that some automatic memory release occurs under certain circumstances?
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 11:01 pm
by Roberto Lopez
Claudio:
A clue:
I've modified the test program to capture the desktop and then release the bitmap WITHOUT saving (not calling BT_BitmapSaveFile) and the memory consumption remained steady across 1000 iterations, so the problem is at saving (BT_BitmapSaveFile).
Re: Bos Taurus problem?
Posted: Fri Sep 16, 2016 11:10 pm
by Roberto Lopez
Another clue:
If in the original (unmodified) example, you change the file extension to '.bmp' all works fine.
So, the problem should be in bt_SaveGDIPlusPicture() used when type is not bmp.
Maybe, there is some memory used and not released there...
Re: Bos Taurus problem?
Posted: Sat Sep 17, 2016 12:05 am
by srvet_claudio
Roberto Lopez wrote:Another clue:
If in the original (unmodified) example, you change the file extension to '.bmp' all works fine.
So, the problem should be in bt_SaveGDIPlusPicture() used when type is not bmp.
Maybe, there is some memory used and not released there...
You are right is a very basic error.
I fixed,
please change the original bt_SaveGDIPlusPicture function in C:\hmg.3.4.3\SOURCE\c_BosTaurus.c (line 686) for this:
I forget to include: GlobalFree (hGlobalAlloc);
Code: Select all
BOOL bt_SaveGDIPlusPicture (HBITMAP hBitmap, TCHAR *FileName, INT TypePicture)
{
CLSID encoderClsid;
BOOL result;
IStream *iStream;
GpImage *image;
WCHAR format [21];
HGLOBAL hGlobalAlloc;
INT ret1, ret2;
WCHAR wFileName [MAX_PATH];
switch (TypePicture)
{
case BT_FILEFORMAT_BMP:
wcscpy (format, L"image/bmp");
break;
case BT_FILEFORMAT_JPG:
wcscpy (format, L"image/jpeg");
break;
case BT_FILEFORMAT_GIF:
wcscpy (format, L"image/gif");
break;
case BT_FILEFORMAT_TIF:
wcscpy (format, L"image/tiff");
break;
case BT_FILEFORMAT_PNG:
wcscpy (format, L"image/png");
break;
default:
return FALSE;
}
if (bt_Load_GDIplus () == FALSE)
return FALSE;
result = bt_GetEncoderCLSID ((WCHAR *)format, &encoderClsid);
if(result == TRUE)
{
hGlobalAlloc = bt_Bitmap_To_Stream (hBitmap);
iStream = NULL;
if (CreateStreamOnHGlobal (hGlobalAlloc, FALSE, &iStream) == S_OK)
{
#ifdef UNICODE
lstrcpy (wFileName, FileName);
#else
MultiByteToWideChar(CP_ACP, 0, FileName, -1, wFileName, MAX_PATH);
#endif
ret1 = GdipLoadImageFromStream(iStream, &image);
ret2 = GdipSaveImageToFile(image, wFileName, &encoderClsid, NULL); // Save the image
iStream->lpVtbl->Release (iStream);
bt_Release_GDIplus ();
GlobalFree (hGlobalAlloc); // ADD, September 2016
if (ret1 == 0 && ret2 == 0)
return TRUE;
else
return FALSE;
}
}
bt_Release_GDIplus ();
return FALSE; // The File encoder is not installed
}