From b58b8cdd30d96fc720e767e3158f286066613cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 1 Feb 2014 10:27:47 +0100 Subject: [PATCH] BView: Fix ClipTo[Inverse]Picture() syncing. When BPictures are created on the stack and go out of scope, they send a AS_DELETE_PICTURE command to the ServerApp thread, and that command may be processed sooner than the AS_VIEW_CLIP_TO_PICTURE command in the ServerWindow thread, causing that command to no longer find a ServerPicture for the given token. Apparently, the Be API leaves you the choice not to sync, in case for example when you cache your BPictures and they remain valid. The default value for "sync" is true. The BeBook could explain the situation better when sync is needed and when not. --- src/kits/interface/View.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 56dd513007..f20295d1e7 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -5092,20 +5092,30 @@ BView::_ClipToPicture(BPicture* picture, BPoint where, bool invert, bool sync) if (!_CheckOwnerLockAndSwitchCurrent()) return; - if (!picture) { + if (picture == NULL) { fOwner->fLink->StartMessage(AS_VIEW_CLIP_TO_PICTURE); fOwner->fLink->Attach(-1); + + // NOTE: No need to sync here, since the -1 token cannot + // become invalid on the server. } else { fOwner->fLink->StartMessage(AS_VIEW_CLIP_TO_PICTURE); fOwner->fLink->Attach(picture->Token()); fOwner->fLink->Attach(where); fOwner->fLink->Attach(invert); - } - // TODO: I think that "sync" means another thing here: - // the bebook, at least, says so. - if (sync) - fOwner->fLink->Flush(); + // NOTE: "sync" defaults to true in public methods. If you know what + // you are doing, i.e. if you know your BPicture stays valid, you + // can avoid the performance impact of syncing. In a use-case where + // the client creates BPictures on the stack, these BPictures may + // have issued a AS_DELETE_PICTURE command to the ServerApp when Draw() + // goes out of scope, and the command is processed earlier in the + // ServerApp thread than the AS_VIEW_CLIP_TO_PICTURE command in the + // ServerWindow thread, which will then have the result that no + // ServerPicture is found of the token. + if (sync) + Sync(); + } }