From 582b3d5a72633f7d6fa55e913fd07f61a9eb1744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 8 Mar 2008 17:41:24 +0000 Subject: [PATCH] * When allocating a new Window, check the allocation of the DrawingEngine instance by introducing Window::InitCheck(), use new (nothrow). * Window is responsible for the DrawingEngine instance, but forgot to delete it. * OffscreenWindow is no longer special, every Window owns a DrawingEngine, no need to delete it anymore, but since it already deletes the HWInterface instance, it needs to detach the DrawingEngine from it. * Use new (nothrow) in OffscreenWindow as well. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24308 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/OffscreenWindow.cpp | 25 +++++++++++++++++-------- src/servers/app/ServerWindow.cpp | 7 +++++-- src/servers/app/Window.cpp | 17 +++++++++++++++-- src/servers/app/Window.h | 2 ++ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/servers/app/OffscreenWindow.cpp b/src/servers/app/OffscreenWindow.cpp index e1e226a635..291b80ea67 100644 --- a/src/servers/app/OffscreenWindow.cpp +++ b/src/servers/app/OffscreenWindow.cpp @@ -9,6 +9,7 @@ #include "OffscreenWindow.h" +#include #include #include @@ -17,15 +18,20 @@ #include "DrawingEngine.h" #include "ServerBitmap.h" +using std::nothrow; + OffscreenWindow::OffscreenWindow(ServerBitmap* bitmap, const char* name, ::ServerWindow* window) : Window(bitmap->Bounds(), name, B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - 0, 0, window, new DrawingEngine()), + 0, 0, window, new (nothrow) DrawingEngine()), fBitmap(bitmap), - fHWInterface(new BitmapHWInterface(fBitmap)) + fHWInterface(new (nothrow) BitmapHWInterface(fBitmap)) { + if (!fHWInterface || !GetDrawingEngine()) + return; + fHWInterface->Initialize(); GetDrawingEngine()->SetHWInterface(fHWInterface); @@ -39,11 +45,14 @@ OffscreenWindow::OffscreenWindow(ServerBitmap* bitmap, OffscreenWindow::~OffscreenWindow() { - fHWInterface->LockExclusiveAccess(); - // Unlike normal windows, we own the DrawingEngine instance - delete GetDrawingEngine(); - fHWInterface->Shutdown(); - fHWInterface->UnlockExclusiveAccess(); - delete fHWInterface; + if (GetDrawingEngine()) + GetDrawingEngine()->SetHWInterface(NULL); + + if (fHWInterface) { + fHWInterface->LockExclusiveAccess(); + fHWInterface->Shutdown(); + fHWInterface->UnlockExclusiveAccess(); + delete fHWInterface; + } } diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 7bfa8b79fc..9d25a8bd0b 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -282,8 +282,11 @@ ServerWindow::Init(BRect frame, window_look look, window_feel feel, // We cannot call MakeWindow in the constructor, since it // is a virtual function! fWindow = MakeWindow(frame, fTitle, look, feel, flags, workspace); - if (!fWindow) + if (!fWindow || fWindow->InitCheck() != B_OK) { + delete fWindow; + fWindow = NULL; return B_NO_MEMORY; + } if (!fWindow->IsOffscreenWindow()) { fDesktop->AddWindow(fWindow); @@ -2999,7 +3002,7 @@ ServerWindow::MakeWindow(BRect frame, const char* name, // The non-offscreen ServerWindow uses the DrawingEngine instance from // the desktop. return new (nothrow) ::Window(frame, name, look, feel, flags, - workspace, this, new DrawingEngine(fDesktop->HWInterface())); + workspace, this, new (nothrow) DrawingEngine(fDesktop->HWInterface())); } diff --git a/src/servers/app/Window.cpp b/src/servers/app/Window.cpp index fe08ea80e8..6373c8be42 100644 --- a/src/servers/app/Window.cpp +++ b/src/servers/app/Window.cpp @@ -175,11 +175,24 @@ Window::Window(const BRect& frame, const char *name, Window::~Window() { - if (fTopView) + if (fTopView) { fTopView->DetachedFromWindow(); + delete fTopView; + } - delete fTopView; delete fDecorator; + + delete fDrawingEngine; +} + + +status_t +Window::InitCheck() const +{ + if (!fDrawingEngine) + return B_NO_MEMORY; + // TODO: anything else? + return B_OK; } diff --git a/src/servers/app/Window.h b/src/servers/app/Window.h index 3f07c7bf3f..b5ec991aa6 100644 --- a/src/servers/app/Window.h +++ b/src/servers/app/Window.h @@ -50,6 +50,8 @@ public: DrawingEngine* drawingEngine); virtual ~Window(); + status_t InitCheck() const; + BRect Frame() const { return fFrame; } const char* Title() const { return fTitle.String(); }