Fix last > rowCount() assert in ClassModel Node dtor

Authored by buschinski on Aug 14 2018, 3:21 PM.



This patch fixes another assert in the classmodel.
This time it is the assert triggered from
Node::~Node -> ClassModel::nodesAboutToBeRemoved -> QAbstractItemModel::beginRemoveRows(index, first, last)

last > rowCount(), last was greater than the rowCount.

This is because in Node::removeNode the child was first removed from the childrenlist and then deleted.
But createIndex() & rowCount() rely on the item to still be in the model/list. Node::row() would simply return -1 which would result in an invalid index.

rowCount for invalid index < last Item

The solution is simple, like in Node::clear(), first delete the item and then remove it from the list.

Test Plan
  • compile Qt 5.11.1 with debug&asserts enabled
  • compile kdevelop against this version of Qt
  • start kdevelop and open a project
  • open the Classes toolview
  • expand & collapse some items

-> assert/crash

Diff Detail

R32 KDevelop
Lint Skipped
Unit Tests Skipped
buschinski created this revision.Aug 14 2018, 3:21 PM
Restricted Application added a project: KDevelop. · View Herald TranscriptAug 14 2018, 3:21 PM
Restricted Application added a subscriber: kdevelop-devel. · View Herald Transcript
buschinski requested review of this revision.Aug 14 2018, 3:21 PM
brauch accepted this revision.Aug 14 2018, 3:41 PM
brauch added a subscriber: brauch.

Somehow I find the code rather strange, with the destructor removing items from the item model ...
But ok, if you tried it out and it fixes the problem, I guess it's fine.

This revision is now accepted and ready to land.Aug 14 2018, 3:41 PM
buschinski closed this revision.Aug 14 2018, 6:50 PM