Bos Taurus problem?

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Bos Taurus problem?

Post 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.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Bos Taurus problem?

Post by Roberto Lopez »

I've forgot to mention that I've tested on Windows 7 32 bits and Windows 8.1 64 bits.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Bos Taurus problem?

Post by srvet_claudio »

Roberto,
Thanks for report. I will check.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Bos Taurus problem?

Post 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 4621 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Bos Taurus problem?

Post 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 :)
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Bos Taurus problem?

Post 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 4620 times
Last edited by andyglezl on Fri Sep 16, 2016 1:34 am, edited 1 time in total.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Bos Taurus problem?

Post 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...
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Bos Taurus problem?

Post 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...
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Bos Taurus problem?

Post by Roberto Lopez »

And the fact that a complete different routine like the old SaveWIndowByHandle() creates a similar problem, is very strange...
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Bos Taurus problem?

Post 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...
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply