[Interest] QGraphicsScene crash after removeItem() and delete item

Volker Poplawski volker at openbios.org
Thu Nov 29 12:33:58 CET 2012


Hi everybody,

I'm facing segfault in succession of deleting a number of QGraphicsItems from a scene.

The following code leads to the stack trace below on the next redraw of the scene.

  while (not m_items.isEmpty())
  {
    QGraphicsItem *item = m_items.takeFirst();
    m_scene->removeItem(item);  // qtdoc says it's faster to remove item first then delete
    delete item;
  }


The interesting things is that without the removeItem() call, i.e. just calling delete on the items, my program does not crash.






0	QGraphicsSceneFindItemBspTreeVisitor::visit(QList<QGraphicsItem*>*)			0x1075cff	
1	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074c40	
2	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074ce0	
3	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074c40	
4	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074c40	
5	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074c40	
6	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074c40	
7	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074c40	
8	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074c40	
9	QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const			0x1074ce0	
10	QGraphicsSceneBspTree::items(QRectF const&, bool) const			0x107539e	
11	QGraphicsSceneBspTreeIndexPrivate::estimateItems(QRectF const&, Qt::SortOrder, bool)			0xf24058	
12	QGraphicsSceneBspTreeIndex::estimateTopLevelItems(QRectF const&, Qt::SortOrder) const			0xf24233	
13	QGraphicsScenePrivate::drawItems(QPainter*, QTransform const*, QRegion*, QWidget*)			0xf194ad	
14	QGraphicsView::paintEvent(QPaintEvent*)			0xf3505c	
15	QWidget::event(QEvent*)			0xa6941a	
16	QFrame::event(QEvent*)			0xd81236	
17	QGraphicsView::viewportEvent(QEvent*)			0xf362bb	
18	QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*)			0x11992b7	
19	QApplicationPrivate::notify_helper(QObject*, QEvent*)			0xa240f1	
20	QApplication::notify(QObject*, QEvent*)			0xa2c63f	
...	<More>				





....Volker



More information about the Interest mailing list