[haiku-3rdparty-dev] Re: Drawing into a BBitmap using a BView

  • From: "Matthew Allen" <fret@xxxxxxxxxxxx>
  • To: <haiku-3rdparty-dev@xxxxxxxxxxxxx>
  • Date: Wed, 12 Jun 2013 12:55:07 +1000

---------- Original Message ----------
To:  <haiku-3rdparty-dev@xxxxxxxxxxxxx>
From: Rene Gollent (anevilyak@xxxxxxxxx)
Subject: [haiku-3rdparty-dev] Re: Drawing into a BBitmap using a BView
Date: 12/06/2013 10:39:41a

> On Tue, Jun 11, 2013 at 7:11 PM, Matthew Allen <fret@xxxxxxxxxxxx> wrote:
>
> > Is this supported in Haiku? (I do seem to remember it working in r5).
>
> This is supported and used in various places in Haiku itself. Two main
> possibilities come to mind from a brief look at your code: 1) The
> bitmap needs to be locked while you're drawing into it, and I don't
> see where you're doing so,

GDisplayString.cpp:953 has this bit:

        GLocker Locker(Hnd, _FL); // _FL is just __FILE__, __LINE__ screw 
typing that out hundreds of times ;-)
        Locker.Lock();

Thats my wrapper around BHandler::LockLooper()/UnlockLooper() that also tracks 
the File/Line number of the locker. So I can at any point see which thread is 
locking what. So if at some point I get a dead lock I can query the GLocker 
class's static GetLocker method to work out which bit of code is at fault. And 
being an object, as it goes out of scope it automatically unlocks things, so I 
don't have to worry about stray returns leaving the Lock/Unlock sets unbalanced.

It crashes without the lock, so I added that fairly early on.

> and 2) You may also need to call Sync() on
> the child view after you finish your drawing operations to ensure
> they're committed to the bitmap.

That worked!

Thanks.
--
Matthew Allen


Other related posts: