BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TBitmap lost during gdi ops

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Ron Lange
Guest





PostPosted: Wed Oct 12, 2005 3:24 pm    Post subject: TBitmap lost during gdi ops Reply with quote



Hi,
I'm just starting with a short description what's to do and what's
happening then:

Triggered by mouse motion a paricular region of a dc have to be restored
from a TBitmap, then a new region have to be saved into this TBitmap.
After a while the bitmap handle seems to be valid but the actual bitmap
on which it is pointing contains no data anymore. Since the operations
are locked by semaphores the exclusive access to the bitmap should be
guaranteed.

1. Are there any limitations in usage of vcl bitmaps for gdi ops
2. Should I use gdi bitmaps instead?

thanks
Ron
Back to top
Oliver Rutsch
Guest





PostPosted: Fri Oct 14, 2005 8:27 am    Post subject: Re: TBitmap lost during gdi ops Reply with quote



Hi Ron,

Quote:
Hi,
I'm just starting with a short description what's to do and what's
happening then:

Triggered by mouse motion a paricular region of a dc have to be restored
from a TBitmap, then a new region have to be saved into this TBitmap.
After a while the bitmap handle seems to be valid but the actual bitmap
on which it is pointing contains no data anymore. Since the operations
are locked by semaphores the exclusive access to the bitmap should be
guaranteed.

1. Are there any limitations in usage of vcl bitmaps for gdi ops
2. Should I use gdi bitmaps instead?


First Question: Are you accessing the TBitmap from a thread? If so, then
I discovered the same type of problems with the VCL Canvas as you,
regardless if you're using Canvas->Lock() or some other type of sync
object.
I had a situation where I tried to draw in a thread on a TBitmap (with a
locked Canvas!) and after a while the handle of the canvas suddenly got
invalid and all the painting stopped. There was no deadlocking or a race
condition, just the canvas handle got corrupted.
Then I used only pure WIN-API functions to draw on the DC and everything
was fine after that. So I assume that the VCL has serious problems with
multithreading. I found some other VCL classes (like TStream), who have
also multithreading problems (all classes where correctly locked by
critical sections!). So I try to avoid these situations.

I would suggest to draw only with API functions on your TBitmap from a
thread, for example:

RECT ScreenRect={0,0,mBitmap->Width,mBitmap->Width};
HDC hdcCompatible = CreateCompatibleDC(NULL);
if (!hdcCompatible)
throw Exception("CreateCompatibleDC failed!");
if (!SelectObject(hdcCompatible, mBitmap->Handle))
throw Exception("SelectObject failed!");
FillRect(hdcCompatible,&ScreenRect,mBitmap->Canvas->Brush->Handle);
DeleteDC(hdcCompatible);

If you're not working with multithreading, then your semaphore is
useless and there has to be some other type of problem. Posting some
code would be helpful then.
TBitmap is just a wrapper for GDI bitmaps so normally it has no limitations.

Hope this helps.

Bye, Oliver


Back to top
Ron Lange
Guest





PostPosted: Fri Oct 21, 2005 2:59 pm    Post subject: Re: TBitmap lost during gdi ops Reply with quote



Hi Oliver
Oliver Rutsch schrieb:
....
Quote:
I would suggest to draw only with API functions on your TBitmap from a
thread, for example:
....

Yes, it is a multithreaded application. I'm about to replace all
graphics related things in our project by win-api counterparts. Actually
I thought just replacing the operation by pure gdi ops would make my day
but it seems to be nescessary to also change the Graphics::TBitmap by
winapi TBitmaps.

Quote:
...
Hope this helps.

Bye, Oliver

It is good to see somebody other had the same kind of trouble with vcl
graphics Wink
By
Ron

Back to top
Oliver Rutsch
Guest





PostPosted: Mon Oct 24, 2005 7:27 am    Post subject: Re: TBitmap lost during gdi ops Reply with quote

Hi Ron,

Quote:
I thought just replacing the operation by pure gdi ops would make my day
but it seems to be nescessary to also change the Graphics::TBitmap by
winapi TBitmaps.


If you're looking for "TBitmap and thread" then you'll find several
postings in the delphi and cppbuilder groups.
Most of them recommend not to use TBitmap in threads. And that's what
I'm doing in my code, too.
I looked at the delphi source code for TBitmap and there is some kind of
locking, but it seems that it wasn't tested very well.
So let's hope that it'll be better in Dexter, although my trust in
Borlands power to work on these things isn't very distinctive.

Bye, Oliver

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.