Qt-interest Archive, December 2006
QGraphicsScene keeps pointer to removed Items?
Message 1 in thread
On Qt 4.2.1 Debian Unstable:
While adding and removing QGraphicsItems to my QGraphicsScene the application
crashes at: qgraphicsscene_bsp.cpp:
58 if (!item->d_func()->itemDiscovered && item->isVisible()) {
After adding some debug output (also in src/gui/graphicsscene_bsp.cpp) this
happened with Pointer 0x8219298:
GDB Session and debug output
-----------------------------------------------------------------------------------------------------------------------------------------------------------
qgraphicsscene_bsp.cpp:58 QGraphicsItem *item=0x8134158
qgraphicsscene_bsp.cpp:58 QGraphicsItem *item=0x8219298 <--
---------
<--SNIP-->
qgraphicsscene_bsp.cpp:58 QGraphicsItem *item=0x8293890
killfest!
killing: 0x8219298 <-- At this point the item is removed with
scene->removeItem(...) and delete.
destructor edgeitem this=0x8219290
killing: 0x80cd0d0
<--SNIP-->
destructor stateitem this=0x82567d0
qgraphicsscene_bsp.cpp:58 QGraphicsItem *item=0x8268448
<--SNIP-->
qgraphicsscene_bsp.cpp:58 QGraphicsItem *item=0x827a8f0
qgraphicsscene_bsp.cpp:58 QGraphicsItem *item=0x8219298 <-- At this point in
time the item appears again in qgraphicsscene_bsp.cpp:58
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1222965024 (LWP 10083)]
0xb7daafbd in QGraphicsSceneFindItemBspTreeVisitor::visit (this=0x80bb238,
items=0x812fec0) at graphicsview/qgraphicsscene_bsp.cpp:58
58 if (!item->d_func()->itemDiscovered && item->isVisible()) {
(gdb) p item
$1 = (class QGraphicsItem *) 0x8219298 <--
(gdb) whatis item
type = class QGraphicsItem *
(gdb) The program is running. Exit anyway? (y or n)
-----------------------------------------------------------------------------------------------------------------------------------------------------------
It looks like I'm not able to reproduce the bug with:
1. QGraphicsScene::setItemIndexMethod(NoIndex) (Duh).
2. Also if i use the default implementation of
QGraphicsPathItem::boundingRect() everything seems to work. My implementation
which leads to the bug draws an additional arrow head at the end of the path
and expands the boundingrect:
QRectF ArrowItem::boundingRect() const {
QPainterPath line = constructLine(); //some method that returns the path.
int w = linePen.width(); //you know this one
return QGraphicsPathItem::boundingRect().united(
constructArrow(line).boundingRect().adjusted(-w, -w, w, w));
}
The items are moved around by the mouse, by algorithms and so on. It takes
quite a few attempts to get a SIGSEGV. Any help is appreciated :)
Cheers Robert
--
[ signature omitted ]