 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ron Lange Guest
|
Posted: Wed Oct 12, 2005 3:24 pm Post subject: TBitmap lost during gdi ops |
|
|
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
|
Posted: Fri Oct 14, 2005 8:27 am Post subject: Re: TBitmap lost during gdi ops |
|
|
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
|
Posted: Fri Oct 21, 2005 2:59 pm Post subject: Re: TBitmap lost during gdi ops |
|
|
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
By
Ron
|
|
| Back to top |
|
 |
Oliver Rutsch Guest
|
Posted: Mon Oct 24, 2005 7:27 am Post subject: Re: TBitmap lost during gdi ops |
|
|
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 |
|
 |
|
|
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
|
|