Page 1 of 3

Bos Taurus problem?

Posted: Thu Sep 15, 2016 10:55 pm
by Roberto Lopez
Hi Claudio (and all),

I've created an app to monitor a PC.

Basically it takes a screenshot of desktop window each 30 seconds and uploads it to an FTP server.

I've noted that after 467 iterations, it stops working.

I've tried on different machines with the same result.

Since I need capture the desktop window and not an HMG one, I've made very little modification to BT_BitmapCaptureClientArea() function to make it work with a handle instead an HMG window name.

I've created the simplest possible example to verify the problem... here it is:

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

	hDesktop := BT_SCR_GETDESKTOPHANDLE()

	nDesktopWidth := GetDesktopWidth()
	nDesktopHeight := GetDesktopHeight()

	for i := 1 to 1000
		xSaveWindowByHandle ( hDesktop , strzero(i,4)  + '.' + 'jpg' , 0 , 0 , nDesktopWidth , nDesktopHeight )		
	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

Thanks in advance.

Re: Bos Taurus problem?

Posted: Thu Sep 15, 2016 11:52 pm
by Roberto Lopez
I've forgot to mention that I've tested on Windows 7 32 bits and Windows 8.1 64 bits.

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 12:23 am
by srvet_claudio
Roberto,
Thanks for report. I will check.

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 1:07 am
by andyglezl
Hola Roberto

Aquí, llega hasta la imagen 608 y es una imagen negra con solo 17kb. a diferencia de
las otras que son de 143kb.

Tengo Win7, SP1 32bits.
pictures.jpg
pictures.jpg (423.4 KiB) Viewed 4622 times

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 1:23 am
by Roberto Lopez
srvet_claudio wrote:Roberto,
Thanks for report. I will check.
I'm keep testing and I'm discovered something really really disturbing...

I've created an equivalent test example with an old HMG version (3.0.40) and used the SaveWindowByHandle() internal function.

The result is the same... only changing the number of files created prior the crash...

mmm... I'm lost :)

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 1:28 am
by andyglezl
extraño... ahora llegó a la 605. la ultima es una pantalla negra.

Me quedé sin memoria...
ram.jpg
ram.jpg (225.14 KiB) Viewed 4621 times

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 1:29 am
by Roberto Lopez
andyglezl wrote:Hola Roberto

Aquí, llega hasta la imagen 608 y es una imagen negra con solo 17kb. a diferencia de
las otras que son de 143kb.

Tengo Win7, SP1 32bits.

pictures.jpg
I'm not sure, but, apparently it depends on desktop size...

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 1:31 am
by Roberto Lopez
andyglezl wrote:extraño... ahora llegó a la 605. la ultima es una pantalla negra.
These kind of errors, usually are related with handles or memory not released... but I can't find it...

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 1:33 am
by Roberto Lopez
And the fact that a complete different routine like the old SaveWIndowByHandle() creates a similar problem, is very strange...

Re: Bos Taurus problem?

Posted: Fri Sep 16, 2016 2:11 am
by Roberto Lopez
andyglezl wrote:extraño... ahora llegó a la 605. la ultima es una pantalla negra.

Me quedé sin memoria...
That's it!

Memory use grows with each screenshot and when is near to the point of no physical memory available, it stops creating images.

The question is why...

Appears to be memory allocated but not released... but... it is not obvious looking at the code...