* 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
This commit is contained in:
Stephan Aßmus 2008-03-08 17:41:24 +00:00
parent f875a78340
commit 582b3d5a72
4 changed files with 39 additions and 12 deletions

View File

@ -9,6 +9,7 @@
#include "OffscreenWindow.h"
#include <new>
#include <stdio.h>
#include <Debug.h>
@ -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;
}
}

View File

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

View File

@ -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;
}

View File

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