From c54e6db4ec49ae109b0f57b6a29a9a5a8419e1f5 Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Mon, 29 May 2023 20:50:51 +0200 Subject: [PATCH] 1.9.6 --- CHANGELOG.md | 1 + .../MiscHelpers/Common/TreeItemModel.cpp | 28 +++++++++++++------ .../MiscHelpers/Common/TreeItemModel.h | 13 +++++++-- SandboxiePlus/SandMan/Models/MonitorModel.h | 4 +-- SandboxiePlus/SandMan/Models/SbieModel.h | 4 +-- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0008f17fc..eba5a7e30b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - fixed Regression: DLL loading problem (Entry Point Not Found) [#2980](https://github.com/sandboxie-plus/Sandboxie/issues/2980) - fixed [1.9.4/5] Sandboxie does not mark deleted files or registry keys while virtualization scheme v2 is active [#2984](https://github.com/sandboxie-plus/Sandboxie/issues/2984) - fixed SandMan: Timestamp of the Sandboxie.ini [#2985](https://github.com/sandboxie-plus/Sandboxie/issues/2985) +- fixed [Plus UI] Crash after pressing the button "Show NT Object Tree" several times [#2943](https://github.com/sandboxie-plus/Sandboxie/issues/2943) diff --git a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp index 7ef50a0623..b2897c7c5e 100644 --- a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp +++ b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp @@ -349,7 +349,8 @@ void CTreeItemModel::RemoveIndex(const QModelIndex &index) return; STreeNode* pNode = static_cast(index.internalPointer()); - ASSERT(pNode); + if (!m_Nodes.contains(pNode)) + return; QHash Old; Old[pNode->ID] = pNode; @@ -367,7 +368,8 @@ bool CTreeItemModel::setData(const QModelIndex &index, const QVariant &value, in if(index.column() == FIRST_COLUMN && role == Qt::CheckStateRole) { STreeNode* pNode = static_cast(index.internalPointer()); - ASSERT(pNode); + if (!m_Nodes.contains(pNode)) + return false; emit CheckChanged(pNode->ID, value.toInt() != Qt::Unchecked); return true; } @@ -380,7 +382,8 @@ QVariant CTreeItemModel::GetItemID(const QModelIndex& index) const return QVariant(); STreeNode* pNode = static_cast(index.internalPointer()); - + if (!m_Nodes.contains(pNode)) + return QVariant(); return pNode->ID; } @@ -393,7 +396,8 @@ QVariant CTreeItemModel::Data(const QModelIndex &index, int role, int section) c // return QSize(64,16); // for fixing height STreeNode* pNode = static_cast(index.internalPointer()); - ASSERT(pNode); + if (!m_Nodes.contains(pNode)) + return QVariant(); return NodeData(pNode, role, section); } @@ -496,8 +500,11 @@ QModelIndex CTreeItemModel::index(int row, int column, const QModelIndex &parent STreeNode* pParent; if (!parent.isValid()) pParent = m_Root; - else - pParent = static_cast(parent.internalPointer()); + else { + pParent = static_cast(parent.internalPointer()); + if (!m_Nodes.contains(pParent)) + return QModelIndex(); + } if(STreeNode* pNode = pParent->Children.count() > row ? pParent->Children[row] : NULL) return createIndex(row, column, pNode); @@ -510,6 +517,8 @@ QModelIndex CTreeItemModel::parent(const QModelIndex &index) const return QModelIndex(); STreeNode* pNode = static_cast(index.internalPointer()); + if (!m_Nodes.contains(pNode)) + return QModelIndex(); ASSERT(pNode->Parent); STreeNode* pParent = pNode->Parent; if (pParent == m_Root) @@ -529,8 +538,11 @@ int CTreeItemModel::rowCount(const QModelIndex &parent) const STreeNode* pNode; if (!parent.isValid()) pNode = m_Root; - else - pNode = static_cast(parent.internalPointer()); + else { + pNode = static_cast(parent.internalPointer()); + if (!m_Nodes.contains(pNode)) + return 0; + } return pNode->Children.count(); } diff --git a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h index 7487fae763..2dc718ed96 100644 --- a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h +++ b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h @@ -49,7 +49,7 @@ public slots: protected: struct STreeNode { - STreeNode(const QVariant& Id) { + STreeNode(CTreeItemModel* pModel, const QVariant& Id) { ID = Id; Parent = NULL; Row = 0; @@ -59,8 +59,13 @@ public slots: IsBold = false; IsGray = false; + + Model = pModel; + Model->m_Nodes.insert(this); + } + virtual ~STreeNode(){ + Model->m_Nodes.remove(this); } - virtual ~STreeNode(){} QVariant ID; @@ -83,6 +88,7 @@ public slots: QVariant Formatted; }; QVector Values; + CTreeItemModel* Model; }; virtual QVariant NodeData(STreeNode* pNode, int role, int section) const; @@ -105,6 +111,7 @@ public slots: STreeNode* m_Root; QHash m_Map; + QSet m_Nodes; bool m_bUseIcons; static bool m_DarkMode; @@ -129,7 +136,7 @@ class MISCHELPERS_EXPORT CSimpleTreeModel : public CTreeItemModel virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; protected: - virtual STreeNode* MkNode(const QVariant& Id) { return new STreeNode(Id); } + virtual STreeNode* MkNode(const QVariant& Id) { return new STreeNode(this, Id); } virtual void FreeNode(STreeNode* pNode) { delete pNode; } QList MakePath(const QVariantMap& Cur, const QMap& List); diff --git a/SandboxiePlus/SandMan/Models/MonitorModel.h b/SandboxiePlus/SandMan/Models/MonitorModel.h index 4f3d65f41a..00a228de70 100644 --- a/SandboxiePlus/SandMan/Models/MonitorModel.h +++ b/SandboxiePlus/SandMan/Models/MonitorModel.h @@ -79,12 +79,12 @@ class CMonitorModel : public CTreeItemModel protected: struct STraceNode : STreeNode { - STraceNode(const QVariant& Id) : STreeNode(Id) { } + STraceNode(CTreeItemModel* pModel, const QVariant& Id) : STreeNode(pModel, Id) { } CMonitorEntryPtr pEntry; }; - virtual STreeNode* MkNode(const QVariant& Id) { return new STraceNode(Id); } + virtual STreeNode* MkNode(const QVariant& Id) { return new STraceNode(this, Id); } virtual STreeNode* MkVirtualNode(const QVariant& Id, STreeNode* pParent); bool m_bObjTree; diff --git a/SandboxiePlus/SandMan/Models/SbieModel.h b/SandboxiePlus/SandMan/Models/SbieModel.h index 4f72ba3635..20b26b19d8 100644 --- a/SandboxiePlus/SandMan/Models/SbieModel.h +++ b/SandboxiePlus/SandMan/Models/SbieModel.h @@ -67,7 +67,7 @@ class CSbieModel : public CTreeItemModel struct SSandBoxNode: STreeNode { - SSandBoxNode(const QVariant& Id) : STreeNode(Id) { inUse = false; bOpen = false; busyState = 0; boxType = -1; boxDel = false; boxNoForce = false; boxColor = 0; OrderNumber = 0; } + SSandBoxNode(CTreeItemModel* pModel, const QVariant& Id) : STreeNode(pModel, Id) { inUse = false; bOpen = false; busyState = 0; boxType = -1; boxDel = false; boxNoForce = false; boxColor = 0; OrderNumber = 0; } CSandBoxPtr pBox; bool inUse; @@ -85,7 +85,7 @@ class CSbieModel : public CTreeItemModel virtual QVariant NodeData(STreeNode* pNode, int role, int section) const; - virtual STreeNode* MkNode(const QVariant& Id) { return new SSandBoxNode(Id); } + virtual STreeNode* MkNode(const QVariant& Id) { return new SSandBoxNode(this, Id); } QList MakeProcPath(const QString& BoxName, const CBoxedProcessPtr& pProcess, const QMap& ProcessList); void MakeProcPath(const CBoxedProcessPtr& pProcess, const QMap& ProcessList, QList& Path);