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(); }