From 20e9aae466a0945ddcb883f6dce986534b0887ab Mon Sep 17 00:00:00 2001 From: Thorvald Natvig Date: Sat, 10 May 2008 11:14:08 +0000 Subject: [PATCH] Fix crash when moving populated channels to parents. git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@1154 05730e5d-ab1b-0410-a4ac-84af385074fa --- src/mumble/PlayerModel.cpp | 30 ++++++++++++++++++------------ src/mumble/PlayerModel.h | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/mumble/PlayerModel.cpp b/src/mumble/PlayerModel.cpp index 1746b6bd0..02cdcd6e0 100644 --- a/src/mumble/PlayerModel.cpp +++ b/src/mumble/PlayerModel.cpp @@ -58,14 +58,23 @@ ModelItem::ModelItem(ClientPlayer *p) { } ModelItem::ModelItem(ModelItem *i) { - // Create a dummy clone. + // Create a full clone this->cChan = i->cChan; this->pPlayer = i->pPlayer; this->parent = i->parent; + if (pPlayer) c_qhPlayers.insert(pPlayer, this); else if (cChan) c_qhChannels.insert(cChan, this); + + iPlayers = i->iPlayers; + + foreach(ModelItem *child, i->qlChildren) { + ModelItem *ni = new ModelItem(child); + ni->parent = this; + qlChildren << ni; + } } ModelItem::~ModelItem() { @@ -77,15 +86,13 @@ ModelItem::~ModelItem() { c_qhPlayers.remove(pPlayer); } -void ModelItem::stealChildren(ModelItem *other) { - Q_ASSERT(qlChildren.count() == 0); - - qlChildren = other->qlChildren; - other->qlChildren.clear(); - foreach(ModelItem *mi, qlChildren) - mi->parent = this; - iPlayers = other->iPlayers; - other->iPlayers = 0; +void ModelItem::wipe() { + foreach(ModelItem *i, qlChildren) { + i->wipe(); + delete i; + } + qlChildren.clear(); + iPlayers = 0; } ModelItem *ModelItem::child(int idx) const { @@ -501,8 +508,6 @@ void PlayerModel::moveItem(ModelItem *oldparent, ModelItem *newparent, ModelItem newparent->cChan->addPlayer(item->pPlayer); } - t->stealChildren(item); - endInsertRows(); changePersistentIndex(createIndex(oldrow, 0, item), createIndex(newrow, 0, t)); @@ -511,6 +516,7 @@ void PlayerModel::moveItem(ModelItem *oldparent, ModelItem *newparent, ModelItem oldparent->qlChildren.removeAt(oldrow); endRemoveRows(); + item->wipe(); delete item; if (active.isValid()) { diff --git a/src/mumble/PlayerModel.h b/src/mumble/PlayerModel.h index ffe1897e3..c00c7a518 100644 --- a/src/mumble/PlayerModel.h +++ b/src/mumble/PlayerModel.h @@ -75,7 +75,7 @@ struct ModelItem { int rows() const; int insertIndex(Channel *c) const; int insertIndex(ClientPlayer *p) const; - void stealChildren(ModelItem *other); + void wipe(); }; class ChannelItem;