From c8fe174643c5f5b206e15fb93a1bbd7fb81f74b6 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Sun, 5 Oct 2008 21:11:20 +0000 Subject: [PATCH] * fix a crash when closing Cortex with some connected nodes This should have crashed on R5 too, what happend is that deleting a 'Box' will cause a release of it's EndPoints, thus leaving some dangling EndPoint pointers in the Wires, which they access to call disconnect. So deletion order is important here, delete Wires first. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27880 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../cortex/DiagramView/DiagramItemGroup.cpp | 41 +++++++++++-------- .../cortex/MediaRoutingView/MediaJack.cpp | 4 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/apps/cortex/DiagramView/DiagramItemGroup.cpp b/src/apps/cortex/DiagramView/DiagramItemGroup.cpp index 7c8937657d..c151ed88b0 100644 --- a/src/apps/cortex/DiagramView/DiagramItemGroup.cpp +++ b/src/apps/cortex/DiagramView/DiagramItemGroup.cpp @@ -37,37 +37,40 @@ DiagramItemGroup::DiagramItemGroup(uint32 acceptedTypes, bool multiSelection) DiagramItemGroup::~DiagramItemGroup() { D_METHOD(("DiagramItemGroup::~DiagramItemGroup()\n")); - if (fSelection) { - fSelection->MakeEmpty(); - delete fSelection; - } - - if (fBoxes && (fTypes & DiagramItem::M_BOX)) { - while (CountItems(DiagramItem::M_BOX) > 0) { - DiagramItem *item = ItemAt(0, DiagramItem::M_BOX); - if (RemoveItem(item)) - delete item; - } - delete fBoxes; - } + int32 count = 0; if (fWires && (fTypes & DiagramItem::M_WIRE)) { - while (CountItems(DiagramItem::M_WIRE) > 0) { - DiagramItem *item = ItemAt(0, DiagramItem::M_WIRE); + count = fWires->CountItems(); + for (int32 i = 0; i < count; ++i) { + DiagramItem* item = static_cast(fWires->ItemAtFast(i)); if (RemoveItem(item)) delete item; } delete fWires; } + if (fBoxes && (fTypes & DiagramItem::M_BOX)) { + count = fBoxes->CountItems(); + for (int32 i = 0; i < count; ++i) { + DiagramItem* item = static_cast(fBoxes->ItemAtFast(i)); + if (RemoveItem(item)) + delete item; + } + delete fBoxes; + } + if (fEndPoints && (fTypes & DiagramItem::M_ENDPOINT)) { - while (CountItems(DiagramItem::M_ENDPOINT) > 0) { - DiagramItem *item = ItemAt(0, DiagramItem::M_ENDPOINT); + count = fEndPoints->CountItems(); + for (int32 i = 0; i < count; ++i) { + DiagramItem* item = static_cast(fEndPoints->ItemAtFast(i)); if (RemoveItem(item)) delete item; } delete fEndPoints; } + + if (fSelection) + delete fSelection; } @@ -86,7 +89,6 @@ DiagramItemGroup::CountItems(uint32 whichType) const if (whichType & DiagramItem::M_BOX) { if (fBoxes) count += fBoxes->CountItems(); - } if (whichType & DiagramItem::M_WIRE) { @@ -198,6 +200,9 @@ DiagramItemGroup::AddItem(DiagramItem *item) { D_METHOD(("DiagramItemGroup::AddItem()\n")); if (item && (fTypes & item->type())) { + if (item->m_group) + item->m_group->RemoveItem(item); + switch (item->type()) { case DiagramItem::M_BOX: if (!fBoxes) diff --git a/src/apps/cortex/MediaRoutingView/MediaJack.cpp b/src/apps/cortex/MediaRoutingView/MediaJack.cpp index e0a001a517..c9a9bace91 100644 --- a/src/apps/cortex/MediaRoutingView/MediaJack.cpp +++ b/src/apps/cortex/MediaRoutingView/MediaJack.cpp @@ -376,7 +376,9 @@ void MediaJack::_updateBitmap() tempBitmap->AddChild(tempView); tempView->SetOrigin(0.0, 0.0); - int32 layout = dynamic_cast(view())->getLayout(); + MediaRoutingView* mediaView = dynamic_cast(view()); + int32 layout = mediaView ? mediaView->getLayout() : MediaRoutingView::M_ICON_VIEW; + _drawInto(tempView, tempView->Bounds(), layout); tempView->Sync();