Hi,

I've noticed that if I add a large number of objects to a scene and then start deleting them very quickly (commanded by a keystroke from my parent widget) I can actually crash qgraphicsscene. I'm not sure what's happening, but I get the impression that while I am deleting the objects qgraphicsscene starts a redraw/update and while it's updating I delete more objects and a pointer probably goes null and it crashes.

When I debug my app during the crash I see the second to last function call is:

Qt Code:
  1. class QGraphicsSceneFindItemBspTreeVisitor : public QGraphicsSceneBspTreeVisitor
  2. {
  3. public:
  4. QList<QGraphicsItem *> *foundItems;
  5.  
  6. void visit(QList<QGraphicsItem *> *items)
  7. {
  8. for (int i = 0; i < items->size(); ++i) {
  9. QGraphicsItem *item = items->at(i);
  10. if (!item->d_func()->itemDiscovered && item->isVisible()) {
  11. item->d_func()->itemDiscovered = 1;
  12. foundItems->prepend(item);
  13. }
  14. }
  15. }
  16. };
To copy to clipboard, switch view to plain text mode 

The crash is on the d_func() call.

I've added print statements to make sure I am not leaking objects from the scene and everything looks accounted for. In fact, it appears my delete runs and then a fraction of a second later I get the crash while the scene tries to render.

My code is always calling removeItem() first, then delete;

So is it possible that my delete code is running in one thread while the update runs in another and my delete is running "ahead" of the render which causes a problem?