[Qt-interest] Qt4.4.3 paintEvent thread-safe
Prasanta Sadhukhan
Prasanta.Sadhukhan at Sun.COM
Mon Dec 22 10:13:42 CET 2008
Hi,
I want to know if is it alright to introduce mutex lock/unlock inside a
widget PaintEvent function?
I was getting a crash like below
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 77097872 (LWP 4138)]
0x06ac6bdb in QX11PixmapData::fromImage (this=0xb7403998, img=@0x498502c,
flags=@0x4984f8c) at image/qpixmap_x11.cpp:491
491 const QRgb rgb = p[x];
Current language: auto; currently c++
(gdb) bt
#0 0x06ac6bdb in QX11PixmapData::fromImage (this=0xb7403998,
img=@0x498502c,
flags=@0x4984f8c) at image/qpixmap_x11.cpp:491
#1 0x06ab6633 in QPixmap::fromImage (image=@0x498502c, flags=@0x4985084)
at image/qpixmap.cpp:1876
#2 0x06aecd74 in QPaintEngine::drawImage (this=0x88b7660, r=@0x4985254,
image=@0x88f5648, sr=@0x4985234, flags=@0x4985148)
at painting/qpaintengine.cpp:581
#3 0x06b9a7de in QX11PaintEngine::drawImage (this=0x88b7660, r=@0x4985254,
image=@0x88f5648, sr=@0x4985234, flags=@0x49852c0)
at painting/qpaintengine_x11.cpp:1730
#4 0x06afb5f1 in QPainter::drawImage (this=0x4985354,
targetRect=@0x4985314,
image=@0x88f5648, sourceRect=@0x4985334, flags=@0x4985358)
at painting/qpainter.cpp:4848
#5 0x003d8210 in QtWindow::paintEvent (this=0x88efad0, event=0x49857b8)
at
../../../../../../usr/local/Trolltech/Qt-4.4.3//include/QtGui/qpainter.h:826
#6 0x06a52cb3 in QWidget::event (this=0x88efad0, event=0x49857b8)
at kernel/qwidget.cpp:7301
#7 0x069fa8cf in QApplicationPrivate::notify_helper (this=0x88ca568,
receiver=0x88efad0, e=0x49857b8) at kernel/qapplication.cpp:3803
#8 0x069ff3ae in QApplication::notify (this=0x88bbc48, receiver=0x88efad0,
e=0x49857b8) at kernel/qapplication.cpp:3768
#9 0x023132e9 in QCoreApplication::notifyInternal (this=0x88bbc48,
---Type <return> to continue, or q <return> to quit---
receiver=0x88efad0, event=0x49857b8) at kernel/qcoreapplication.cpp:587
#10 0x06a57dce in qt_sendSpontaneousEvent (receiver=0x88efad0,
event=0xb7403998)
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:212
#11 0x06a4b7e0 in QWidgetPrivate::drawWidget (this=0x88efaf8,
pdev=0x88d3e04,
rgn=@0x4985988, offset=@0x88d9d2c, flags=<value optimized out>,
sharedPainter=0xb74039e0) at kernel/qwidget.cpp:4636
#12 0x06bafde3 in QWidgetBackingStore::cleanRegion (this=0x88d9d20,
rgn=@0x49859ec, widget=0x88efad0, recursiveCopyToScreen=true)
at painting/qbackingstore.cpp:1034
#13 0x06bb1b27 in qt_syncBackingStore (widget=0x88efad0)
at painting/qbackingstore.cpp:313
#14 0x06a52a8f in QWidget::event (this=0x88efad0, event=0xb7400568)
at kernel/qwidget.cpp:7447
#15 0x069fa8cf in QApplicationPrivate::notify_helper (this=0x88ca568,
receiver=0x88efad0, e=0xb7400568) at kernel/qapplication.cpp:3803
#16 0x069ff3ae in QApplication::notify (this=0x88bbc48, receiver=0x88efad0,
e=0xb7400568) at kernel/qapplication.cpp:3768
#17 0x023132e9 in QCoreApplication::notifyInternal (this=0x88bbc48,
receiver=0x88efad0, event=0xb7400568) at kernel/qcoreapplication.cpp:587
#18 0x0231436e in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0,
event_type=0, data=0x88a29e8)
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:209
---Type <return> to continue, or q <return> to quit---
#19 0x0231461d in QCoreApplication::sendPostedEvents (receiver=0x0,
event_type=0) at kernel/qcoreapplication.cpp:1091
#20 0x0233e49f in postEventSourceDispatch (s=0x88d3310)
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:214
#21 0x005187f2 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#22 0x0051b7cf in ?? () from /lib/libglib-2.0.so.0
#23 0x0051bd35 in g_main_context_iteration () from /lib/libglib-2.0.so.0
#24 0x0233e84e in QEventDispatcherGlib::processEvents (this=0x88c5cb0,
flags=@0x4985f8c) at kernel/qeventdispatcher_glib.cpp:319
#25 0x06a8be95 in QGuiEventDispatcherGlib::processEvents (this=0x88c5cb0,
flags=@0x4985fbc) at kernel/qguieventdispatcher_glib.cpp:198
#26 0x0231257d in QEventLoop::processEvents (this=0x4986034,
flags=@0x4985ffc)
at kernel/qeventloop.cpp:143
#27 0x0231270d in QEventLoop::exec (this=0x4986034, flags=@0x498603c)
at kernel/qeventloop.cpp:194
#28 0x023146dd in QCoreApplication::exec () at
kernel/qcoreapplication.cpp:845
#29 0x069fa1c7 in QApplication::exec () at kernel/qapplication.cpp:3331
#30 0x003d9896 in QtApplication::exec (this=0x88bbc48)
at ../../src/share/basis/native/awt/qt/QtApplication.cpp:82
which got solved when I introduced a mutex lock and unlock inside my
PaintEvent function, like this
void QtWindow::paintEvent(QPaintEvent *event)
{
AWT_QT_LOCK;
QPainter p(this);
QPoint pt(0,0);
p.drawImage(pt, *QtImageDescPool[0].offscrSurface);
this->setCursor(QtGraphDescPool[0].qc);
AWT_QT_UNLOCK;
}
But, one problem after I introduced this lock, is one of our benchmark
test is running 4 times slower (90secs compared to 22secs without
lock/unlock).
Can anyone shed some light?
Regards
Prasanta
More information about the Qt-interest-old
mailing list