diff --git a/src/kits/interface/Bitmap.cpp b/src/kits/interface/Bitmap.cpp index 2f9a7d20c4..d5e8b14424 100644 --- a/src/kits/interface/Bitmap.cpp +++ b/src/kits/interface/Bitmap.cpp @@ -217,7 +217,10 @@ BBitmap::BBitmap(const BBitmap *source, bool acceptsViews, */ BBitmap::~BBitmap() { - delete fWindow; + if (fWindow != NULL) { + fWindow->Lock(); + delete fWindow; + } _CleanUp(); } diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index e0fef3431c..e67ea205a6 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -350,18 +350,23 @@ BWindow::BWindow(BRect frame, int32 bitmapToken) BWindow::~BWindow() { - Lock(); - if (BMenu *menu = dynamic_cast(fFocus)) { menu->QuitTracking(); } + // The BWindow is locked when the destructor is called, + // we need to unlock because the menubar thread tries + // to post a message, which will deadlock otherwise. + Unlock(); + // Wait if a menu is still tracking if (fMenuSem > 0) { while (acquire_sem(fMenuSem) == B_INTERRUPTED) ; } + Lock(); + fTopView->RemoveSelf(); delete fTopView;