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:
class QGraphicsSceneFindItemBspTreeVisitor : public QGraphicsSceneBspTreeVisitor
{
public:
QList<QGraphicsItem *> *foundItems;
void visit(QList<QGraphicsItem *> *items)
{
for (int i = 0; i < items->size(); ++i) {
if (!item->d_func()->itemDiscovered && item->isVisible()) {
item->d_func()->itemDiscovered = 1;
foundItems->prepend(item);
}
}
}
};
class QGraphicsSceneFindItemBspTreeVisitor : public QGraphicsSceneBspTreeVisitor
{
public:
QList<QGraphicsItem *> *foundItems;
void visit(QList<QGraphicsItem *> *items)
{
for (int i = 0; i < items->size(); ++i) {
QGraphicsItem *item = items->at(i);
if (!item->d_func()->itemDiscovered && item->isVisible()) {
item->d_func()->itemDiscovered = 1;
foundItems->prepend(item);
}
}
}
};
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?
Bookmarks