FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Possible Bitmap bug
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Possible Bitmap bug
Posted: Wed Sep 08, 2010 05:48 PM
Antonio,

I think I have discovered a bug in the TBitmap class. When calling oBmp:end() the oBrush object contained in the bitmap object is not released. I don't know if all bitmap objects contain a brush but I tried both normal and alpha bitmaps and there was an unreleased brush in both of them. Below is my test code.

This test was done with FWH 10.7.

Regards,
James


Code (fw): Select all Collapse
// Test to show unreleased brush in bitmap object
// Author: James Bott
// Date: 9/8/2010 

#include "fivewin.ch"

Function Main()
   local oWnd, oBmp

   ferase("checkres.txt")

   define window oWnd

   oBmp:= TBitmap(,,,,,"c:\fwh\bitmaps\alphabmp\user.bmp",oWnd) // alpha bitmap
   //oBmp:= TBitmap(,,,,,"c:\fwh\bitmaps\16x16\copy.bmp", oWnd) // regular bitmap

   activate window oWnd

   //oBmp:end() // doesn't release oBitmap:oBrush

   // Need this to release oBitmap
   if (! empty(oBmp:oBrush), oBmp:oBrush:end(),)

   oBmp:end()

   checkRes()

return nil
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Possible Bitmap bug
Posted: Thu Sep 09, 2010 08:19 AM
James,

This code works fine here and checkres.txt is clean:
Code (fw): Select all Collapse
#include "fivewin.ch"

Function Main()
   local oWnd, oBmp

   ferase("checkres.txt")

   define window oWnd

   // oBmp:= TBitmap(,,,,,"c:\fwh\bitmaps\alphabmp\user.bmp",oWnd) // alpha bitmap
   oBmp:= TBitmap(,,,,,"c:\fwh\bitmaps\16x16\copy.bmp", oWnd) // regular bitmap

   activate window oWnd

   oBmp:end()

   checkRes()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Possible Bitmap bug
Posted: Thu Sep 09, 2010 01:20 PM

Antonio,

Hmm. I keep getting this in checkres.txt.

09/09/10 06:18:38: BRUSH,-1223681509,TBITMAP:SETCOLOR(2462)->TBITMAP:DEFINE(265)->MAIN(15)

I will check my paths and libs.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Possible Bitmap bug
Posted: Thu Sep 09, 2010 03:02 PM

James,

I am testing with FWH 10.8 :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Possible Bitmap bug
Posted: Thu Sep 09, 2010 04:23 PM

Antonio,

I am still getting the same unreleased resource with FWH 10.8.

09/09/10 09:21:13: BRUSH,68162367,TBITMAP:SETCOLOR(2463)->TBITMAP:DEFINE(265)->MAIN(15)

I note that the BITMAP.PRGs for 10.7 and 10.8 are identical.

I am running Borland FWH, xHarbour and XP Pro.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Possible Bitmap bug
Posted: Thu Sep 09, 2010 07:09 PM
Antonio,

Well, I am stumped. I don't know why your results are different than mine. I have figured out that the brush is only ended in TWindows which is called by the super:destroy() method in the TBitmap:destroy class, BUT, only if ::nWnd is !=0. It is always equal to 0 in my tests therefore bitmap is not destroyed.

Will someone else run the test code shown in a message above and report back if you find an unreleased brush?

Regards,
James


Code (fw): Select all Collapse
METHOD Destroy() CLASS TBitmap

   if ::hBitmap != 0
      PalBmpFree( ::hBitmap, ::hPalette )
      ::hBitmap  = 0
      ::hPalette = 0
   endif

   if ::oVScroll != nil
      ::oVScroll:End()
   endif

   if ::oHScroll != nil
      ::oHScroll:End()
   endif

msgInfo( ::hWnd, "::hWnd")  // JBott. Always returns 0

   if ::hWnd != 0
      // This calls the TWindow:destoy method which does destroy ::oBrush
      Super:Destroy() // not called because ::hWnd is zero
   endif

  // Added by JBott. This solves the problem.
   if ::oBrush != nil
      ::oBrush:end()
   endif

return nil

//----------------------------------------------------------------------------//
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: Possible Bitmap bug
Posted: Fri Sep 10, 2010 08:27 AM

James

This is what i get , same as you

09/10/10 10:26:00: BRUSH,386931504,TBITMAP:SETCOLOR(2463)->TBITMAP:DEFINE(265)->MAIN(11)

test with fwh 10.8 same code as above

HTH

Richard

http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Possible Bitmap bug
Posted: Fri Sep 10, 2010 02:56 PM

Richard,

Thanks for confirming the problem.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Possible Bitmap bug
Posted: Fri Sep 10, 2010 10:10 PM

James,

What Windows version are you using ? XP as Richard ?

With W7 is fine. I may need to check it with XP.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Possible Bitmap bug
Posted: Fri Sep 10, 2010 11:23 PM

Antonio,

Yes, I am using XP Pro. But, I don't think it is the OS, it seems the logic in the classes is the issue. Look at the Destroy methods in both TBitmap and TWindow. It looks to me like a slight restructuring of the code would fix the problem.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 946
Joined: Thu Oct 06, 2005 07:05 PM
Re: Possible Bitmap bug
Posted: Sat Sep 11, 2010 03:47 AM

Antonio

I am using Windows 7 64 bits

Richard

http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Possible Bitmap bug
Posted: Sat Sep 11, 2010 06:04 AM
James,

This seems a right fix:
Code (fw): Select all Collapse
   if ::hWnd != 0
      Super:Destroy()
   else
      if ::oBrush != nil
         ::oBrush:End()
      endif
   endif

Because if we End() a brush once more than needed we take the risk to destroy the brush that may be in use by other controls.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Possible Bitmap bug
Posted: Mon Sep 13, 2010 04:33 AM

Antonio,

Yes, your code logic looks correct. I had not considered what happens when hWnd !=0 when I wrote my code.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion