[haiku-3rdparty-dev] Locking a window when calling Draw()

  • From: Andrew Wood <andrew@xxxxxxxxxxxxxxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Sun, 26 Feb 2012 17:32:16 +0000

Im trying to fix a bug in a BView derived class which is causing a crash whenever the Draw() method is called for a second or more time. It works OK the first time (when the object is first created) but subsequent calls via Invalidate() cause a crash.


After Googling it seems its necessary to lock the parent window but nothing Ive tried works.

Ive tried

(Window())->LockLooper()

(Window())->UnlockLooper()

and


(Window())->Lock()
(Window())->Unlock()

and numerous other things without success.

The full code for Draw() is here:

void SpeedoDial::Draw(BRect arect)
{
        //lock here?
        MovePenTo(0,0);
        SetDrawingMode(B_OP_ALPHA);
        SetBlendingMode(B_PIXEL_ALPHA,B_ALPHA_OVERLAY);
        if (backend->getMPHMode())
        {
                DrawBitmap(MPHdialimg);
        }
        else
        {       
                DrawBitmap(KMHdialimg);
        }
        //unlock here?
        
}

Im sure Im doing something very simple wrong?

Thanks
Andrew

Other related posts: