简体   繁体   中英

QGraphicsScene::setSceneRect() segmentation fault

I've got a QGraphicsScene to which I'm adding a subclassed QGraphicsRectItem called BorderRect that indicates the boundaries of the sceneRect. The BorderRect has grips that allow the user to change its size, which then changes the scene's sceneRect. All this works, except every once in awhile it causes a seg fault, with a back trace like:

#0  _int_malloc (av=0x7ffff587e620, bytes=32) at malloc.c:3415
#1  0x00007ffff55592a4 in *__GI___libc_malloc (bytes=32) at malloc.c:2924
#2  0x00007ffff5e4c40d in operator new(unsigned long) () from /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6
#3  0x00007ffff723911e in QRegion::QRegion(QRect const&, QRegion::RegionType) () from /usr/lib64/qt4/libQtGui.so.4
#4  0x00007ffff72394de in QRegion::intersect(QRect const&) const () from /usr/lib64/qt4/libQtGui.so.4
#5  0x00007ffff7239509 in QRegion::operator&(QRect const&) const () from /usr/lib64/qt4/libQtGui.so.4
#6  0x00007ffff723952f in QRegion::operator&=(QRect const&) () from /usr/lib64/qt4/libQtGui.so.4
#7  0x00007ffff70e0c6b in QWidgetPrivate::subtractOpaqueSiblings(QRegion&, bool*, bool) const ()
  from /usr/lib64/qt4/libQtGui.so.4
#8  0x00007ffff72b6141 in QWidgetPrivate::scrollRect(QRect const&, int, int) () from /usr/lib64/qt4/libQtGui.so.4
#9  0x00007ffff712fe8a in QWidgetPrivate::scroll_sys(int, int) () from /usr/lib64/qt4/libQtGui.so.4
#10 0x00007ffff70eefe5 in QWidget::scroll(int, int) () from /usr/lib64/qt4/libQtGui.so.4
#11 0x00007ffff76b7fbb in QGraphicsView::scrollContentsBy(int, int) () from /usr/lib64/qt4/libQtGui.so.4
#12 0x00007ffff6b7c0fa in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ()
  from /usr/lib64/qt4/libQtCore.so.4
#13 0x00007ffff770ec7e in QAbstractSlider::valueChanged(int) () from /usr/lib64/qt4/libQtGui.so.4
#14 0x00007ffff76b0dca in QGraphicsViewPrivate::recalculateContentSize() () from /usr/lib64/qt4/libQtGui.so.4
#15 0x00007ffff76bab39 in ?? () from /usr/lib64/qt4/libQtGui.so.4
#16 0x00007ffff6b7c0fa in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ()
  from /usr/lib64/qt4/libQtCore.so.4
#17 0x00007ffff7687a45 in QGraphicsScene::sceneRectChanged(QRectF const&) () from /usr/lib64/qt4/libQtGui.so.4
#18 0x000000000042fef0 in BorderRectItem::sceneEventFilter (this=0xfc0070, watched=0xef6e80, event=0x7fffff800590)
    at gui/BorderRectItem.cpp:193
...

There are several more lines, but the line referred to at line 18 of the back trace corresponds to a call to setSceneRect with a QRectF that corresponds to the new dimensions of the BorderRect, in this case:

{xp = 20, yp = -59, w = 563.94193411401511, h = 436.5631806793956}

I don't know why this is crashing. I've checked the scene, and it's not null. I suspect this is going to be very difficult to debug, and what I'm really interested in is tips on how to go about doing this. In particular, it would be really helpful to check the state of variables in the Qt code as I move up and down through the back trace, and I don't know how to do that. I'm running Linux... can I rebuild Qt with debugging symbols or something?

Just guessing here, but that stack trace makes me suspect, you return reference to local stack QRect from some of your own methods, or reference to some other stack variable (or even explicit pointer to stack variable, but that is harder to do by accident).

And yes, you can compile Qt with debugging symbols, see:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM