* 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:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "OffscreenWindow.h"
|
#include "OffscreenWindow.h"
|
||||||
|
|
||||||
|
#include <new>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
@@ -17,15 +18,20 @@
|
|||||||
#include "DrawingEngine.h"
|
#include "DrawingEngine.h"
|
||||||
#include "ServerBitmap.h"
|
#include "ServerBitmap.h"
|
||||||
|
|
||||||
|
using std::nothrow;
|
||||||
|
|
||||||
|
|
||||||
OffscreenWindow::OffscreenWindow(ServerBitmap* bitmap,
|
OffscreenWindow::OffscreenWindow(ServerBitmap* bitmap,
|
||||||
const char* name, ::ServerWindow* window)
|
const char* name, ::ServerWindow* window)
|
||||||
: Window(bitmap->Bounds(), name,
|
: Window(bitmap->Bounds(), name,
|
||||||
B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
0, 0, window, new DrawingEngine()),
|
0, 0, window, new (nothrow) DrawingEngine()),
|
||||||
fBitmap(bitmap),
|
fBitmap(bitmap),
|
||||||
fHWInterface(new BitmapHWInterface(fBitmap))
|
fHWInterface(new (nothrow) BitmapHWInterface(fBitmap))
|
||||||
{
|
{
|
||||||
|
if (!fHWInterface || !GetDrawingEngine())
|
||||||
|
return;
|
||||||
|
|
||||||
fHWInterface->Initialize();
|
fHWInterface->Initialize();
|
||||||
GetDrawingEngine()->SetHWInterface(fHWInterface);
|
GetDrawingEngine()->SetHWInterface(fHWInterface);
|
||||||
|
|
||||||
@@ -39,11 +45,14 @@ OffscreenWindow::OffscreenWindow(ServerBitmap* bitmap,
|
|||||||
|
|
||||||
OffscreenWindow::~OffscreenWindow()
|
OffscreenWindow::~OffscreenWindow()
|
||||||
{
|
{
|
||||||
fHWInterface->LockExclusiveAccess();
|
if (GetDrawingEngine())
|
||||||
// Unlike normal windows, we own the DrawingEngine instance
|
GetDrawingEngine()->SetHWInterface(NULL);
|
||||||
delete GetDrawingEngine();
|
|
||||||
fHWInterface->Shutdown();
|
if (fHWInterface) {
|
||||||
fHWInterface->UnlockExclusiveAccess();
|
fHWInterface->LockExclusiveAccess();
|
||||||
delete fHWInterface;
|
fHWInterface->Shutdown();
|
||||||
|
fHWInterface->UnlockExclusiveAccess();
|
||||||
|
delete fHWInterface;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -282,8 +282,11 @@ ServerWindow::Init(BRect frame, window_look look, window_feel feel,
|
|||||||
// We cannot call MakeWindow in the constructor, since it
|
// We cannot call MakeWindow in the constructor, since it
|
||||||
// is a virtual function!
|
// is a virtual function!
|
||||||
fWindow = MakeWindow(frame, fTitle, look, feel, flags, workspace);
|
fWindow = MakeWindow(frame, fTitle, look, feel, flags, workspace);
|
||||||
if (!fWindow)
|
if (!fWindow || fWindow->InitCheck() != B_OK) {
|
||||||
|
delete fWindow;
|
||||||
|
fWindow = NULL;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fWindow->IsOffscreenWindow()) {
|
if (!fWindow->IsOffscreenWindow()) {
|
||||||
fDesktop->AddWindow(fWindow);
|
fDesktop->AddWindow(fWindow);
|
||||||
@@ -2999,7 +3002,7 @@ ServerWindow::MakeWindow(BRect frame, const char* name,
|
|||||||
// The non-offscreen ServerWindow uses the DrawingEngine instance from
|
// The non-offscreen ServerWindow uses the DrawingEngine instance from
|
||||||
// the desktop.
|
// the desktop.
|
||||||
return new (nothrow) ::Window(frame, name, look, feel, flags,
|
return new (nothrow) ::Window(frame, name, look, feel, flags,
|
||||||
workspace, this, new DrawingEngine(fDesktop->HWInterface()));
|
workspace, this, new (nothrow) DrawingEngine(fDesktop->HWInterface()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -175,11 +175,24 @@ Window::Window(const BRect& frame, const char *name,
|
|||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
if (fTopView)
|
if (fTopView) {
|
||||||
fTopView->DetachedFromWindow();
|
fTopView->DetachedFromWindow();
|
||||||
|
delete fTopView;
|
||||||
|
}
|
||||||
|
|
||||||
delete fTopView;
|
|
||||||
delete fDecorator;
|
delete fDecorator;
|
||||||
|
|
||||||
|
delete fDrawingEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Window::InitCheck() const
|
||||||
|
{
|
||||||
|
if (!fDrawingEngine)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
// TODO: anything else?
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
DrawingEngine* drawingEngine);
|
DrawingEngine* drawingEngine);
|
||||||
virtual ~Window();
|
virtual ~Window();
|
||||||
|
|
||||||
|
status_t InitCheck() const;
|
||||||
|
|
||||||
BRect Frame() const { return fFrame; }
|
BRect Frame() const { return fFrame; }
|
||||||
const char* Title() const { return fTitle.String(); }
|
const char* Title() const { return fTitle.String(); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user