Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, March 2008
Producer thread and X errors


Message 1 in thread

I've been following the last few mailing list threads with interest, as 
I am currently struggling with a problem which may be related to Qt/X11 
and threads. On a quad-CPU system running Ubuntu 8.04 alpha6 I get the 
following errors after the application has been drawing to the screen 
for a while:

X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
   Extension:    156 (RENDER)
   Minor opcode: 4 (RenderCreatePicture)
   Resource id:  0x33145d9
X Error: RenderBadPicture (invalid Picture parameter) 179
   Extension:    156 (RENDER)
   Minor opcode: 7 (RenderFreePicture)
   Resource id:  0x33145d9
X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
   Major opcode: 53 (X_CreatePixmap)
   Resource id:  0x33145da
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
   Extension:    156 (RENDER)
   Minor opcode: 4 (RenderCreatePicture)
   Resource id:  0x33145da

For the heck of it, I tried disabling the RENDER extension, but similar 
errors still appear after a while:

X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
   Major opcode: 55 (X_CreateGC)
   Resource id:  0x47bf09
X Error: BadGC (invalid GC parameter) 13
   Major opcode: 70 (X_PolyFillRectangle)
   Resource id:  0x47bf09
X Error: BadGC (invalid GC parameter) 13
   Major opcode: 59 (X_SetClipRectangles)
   Resource id:  0x47bf09
X Error: BadGC (invalid GC parameter) 13
   Major opcode: 56 (X_ChangeGC)
   Resource id:  0x47bf09
X Error: BadGC (invalid GC parameter) 13
   Major opcode: 70 (X_PolyFillRectangle)
   Resource id:  0x47bf09
X Error: BadGC (invalid GC parameter) 13
   Major opcode: 60 (X_FreeGC)
   Resource id:  0x47bf09

When these errors appear the application will eventually stop doing any 
screen updates.

Running the same program an a single CPU system (a Gentoo based system) 
shows no such symptoms, which may indicate that it is a threads related 
problem. I've tested and confirmed the behavior on both Qt 4-4 beta1 and 
Qt 4.3.4.

The application has a main thread which handles GUI and similar stuff, 
and a producer thread that feeds stuff to be drawed through signals and 
slots. After the recent threads about Qt and threads, I've made sure 
that the producer thread is actually owned by an object living in 
another thread than the main thread, so that the signal/slot mechanism 
can detect and use QueuedConnection automatically (I've also tested 
forcing this mechanism in the connect call, but the problem remains). 
After instantiating the producer thread in the main thread, I use the 
following call from the main thread to "move" it to its own thread:

   m_demo.moveToThread (&m_demo);

m_demo is a subclass of QThread.

I've tried a couple of other things as well, including calling 
XInitThreads before QApplication is instantiated, but it doesn't change 
anything. I've also put in debug output to make sure that all GUI calls 
_only_ occur from the main thread (and not in the producer thread in 
m_demo). The only connection that should exist between the main thread 
and producer thread is the "emit" call that the producer thread does 
which is received by an object in the main thread.

I've also tried making a minimal application to confirm this behavour 
(replicating the producer thread emitting into the main thread which 
draws some random lines and rectangles), but have not been able to 
trigger the bug there.

Anyway, I'm posting this to see if anybody else have encountered 
anything similar, and/or have any ideas on how I can pin down this bug. 
Regardless, I'll keep looking and follow up when/if I figure it out or 
if I am able to create a minimal application that triggers the same 
behaviour.

Thanks,

Marius K.

--
 [ signature omitted ] 

Message 2 in thread

Brief followup; Massive testing of the app indicates that there is a 
difference based on whether the widget which seems to be causing the 
problem is running inside a dockwidget or not. If it is running inside a 
dockwidget, the problems appears after a while. If it is not running 
inside a dockwidget (using a simple QWidget in a separate window 
instead) I have not (yet) been able to trigger the error.

I've also tried creating a minimal testcase and testing it in similar 
manner (running inside a dockwidget or not), but have not been able to 
trigger the bug there yet.

Posting here in case somebody knows whether there is a potential 
resource leak or similar in the dockwidget related code. Not claiming it 
is, but that's the major difference I have been able to observe so far.

Marius K.

Marius Kjeldahl wrote:
> I've been following the last few mailing list threads with interest, as 
> I am currently struggling with a problem which may be related to Qt/X11 
> and threads. On a quad-CPU system running Ubuntu 8.04 alpha6 I get the 
> following errors after the application has been drawing to the screen 
> for a while:
> 
> X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
>   Extension:    156 (RENDER)
>   Minor opcode: 4 (RenderCreatePicture)
>   Resource id:  0x33145d9
> X Error: RenderBadPicture (invalid Picture parameter) 179
>   Extension:    156 (RENDER)
>   Minor opcode: 7 (RenderFreePicture)
>   Resource id:  0x33145d9
> X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
>   Major opcode: 53 (X_CreatePixmap)
>   Resource id:  0x33145da
> X Error: BadDrawable (invalid Pixmap or Window parameter) 9
>   Extension:    156 (RENDER)
>   Minor opcode: 4 (RenderCreatePicture)
>   Resource id:  0x33145da
> 
> For the heck of it, I tried disabling the RENDER extension, but similar 
> errors still appear after a while:
> 
> X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
>   Major opcode: 55 (X_CreateGC)
>   Resource id:  0x47bf09
> X Error: BadGC (invalid GC parameter) 13
>   Major opcode: 70 (X_PolyFillRectangle)
>   Resource id:  0x47bf09
> X Error: BadGC (invalid GC parameter) 13
>   Major opcode: 59 (X_SetClipRectangles)
>   Resource id:  0x47bf09
> X Error: BadGC (invalid GC parameter) 13
>   Major opcode: 56 (X_ChangeGC)
>   Resource id:  0x47bf09
> X Error: BadGC (invalid GC parameter) 13
>   Major opcode: 70 (X_PolyFillRectangle)
>   Resource id:  0x47bf09
> X Error: BadGC (invalid GC parameter) 13
>   Major opcode: 60 (X_FreeGC)
>   Resource id:  0x47bf09
> 
> When these errors appear the application will eventually stop doing any 
> screen updates.
> 
> Running the same program an a single CPU system (a Gentoo based system) 
> shows no such symptoms, which may indicate that it is a threads related 
> problem. I've tested and confirmed the behavior on both Qt 4-4 beta1 and 
> Qt 4.3.4.
> 
> The application has a main thread which handles GUI and similar stuff, 
> and a producer thread that feeds stuff to be drawed through signals and 
> slots. After the recent threads about Qt and threads, I've made sure 
> that the producer thread is actually owned by an object living in 
> another thread than the main thread, so that the signal/slot mechanism 
> can detect and use QueuedConnection automatically (I've also tested 
> forcing this mechanism in the connect call, but the problem remains). 
> After instantiating the producer thread in the main thread, I use the 
> following call from the main thread to "move" it to its own thread:
> 
>   m_demo.moveToThread (&m_demo);
> 
> m_demo is a subclass of QThread.
> 
> I've tried a couple of other things as well, including calling 
> XInitThreads before QApplication is instantiated, but it doesn't change 
> anything. I've also put in debug output to make sure that all GUI calls 
> _only_ occur from the main thread (and not in the producer thread in 
> m_demo). The only connection that should exist between the main thread 
> and producer thread is the "emit" call that the producer thread does 
> which is received by an object in the main thread.
> 
> I've also tried making a minimal application to confirm this behavour 
> (replicating the producer thread emitting into the main thread which 
> draws some random lines and rectangles), but have not been able to 
> trigger the bug there.
> 
> Anyway, I'm posting this to see if anybody else have encountered 
> anything similar, and/or have any ideas on how I can pin down this bug. 
> Regardless, I'll keep looking and follow up when/if I figure it out or 
> if I am able to create a minimal application that triggers the same 
> behaviour.
> 
> Thanks,
> 
> Marius K.
> 

--
 [ signature omitted ] 

Message 3 in thread

Here's another update. Following advice posted on qt-interest from 
before, I put in code that would cause qt to halt on the first "X Error" 
and ran everything (qt compiled in debug mode) under gdb to be able to 
grab a backtrace when it faults. I've attached the backtrace below.

Based on the look of it, it seems to occur deep inside QTreeView / 
QStyleSheet (or it's subclasses). I'm a bit less sure that it has 
anything to do with threads at this point, and I'm running tests on 
other machines to deny/verify this.

I'll keep digging. I still haven't been able to isolate the behaviour in 
a simple example. It's kind of hard as the bug only manifests itself 
after hours of running...

Marius K.

> X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
>   Extension:    156 (RENDER)
>   Minor opcode: 4 (RenderCreatePicture)
>   Resource id:  0x370bded
> 
> Program received signal SIGFPE, Arithmetic exception.
> [Switching to Thread 0x7ffab1338780 (LWP 18061)]
> 0x00007ffaaff27e2d in qt_x_errhandler (dpy=0x6a1a10, err=0x7fffb9357dd0) at kernel/qapplication_x11.cpp:584
> 584       int z = x / y;
> (gdb) bt
> #0  0x00007ffaaff27e2d in qt_x_errhandler (dpy=0x6a1a10, err=0x7fffb9357dd0) at kernel/qapplication_x11.cpp:584
> #1  0x00007ffaae6dfb6d in _XError () from /usr/lib/libX11.so.6
> #2  0x00007ffaae6e6c1a in ?? () from /usr/lib/libX11.so.6
> #3  0x00007ffaae6e6fa5 in _XReply () from /usr/lib/libX11.so.6
> #4  0x00007ffaae6db8aa in XSync () from /usr/lib/libX11.so.6
> #5  0x00007ffaae6dba4b in ?? () from /usr/lib/libX11.so.6
> #6  0x00007ffaae6e72db in ?? () from /usr/lib/libX11.so.6
> #7  0x00007ffaaf26ecee in XRenderCreatePicture () from /usr/lib/libXrender.so.1
> #8  0x00007ffaaff99441 in QX11PixmapData::fromImage (this=0x2be8e20, img=@0x7fffb935aff0, flags=@0x7fffb935b030)
>     at image/qpixmap_x11.cpp:439
> #9  0x00007ffaaff98353 in QX11PixmapData::fill (this=0x2be8e20, fillColor=@0x7fffb935b280) at image/qpixmap_x11.cpp:1121
> #10 0x00007ffaaff8d0ba in QPixmap::fill (this=0x75dd90, color=@0x7fffb935b280) at image/qpixmap.cpp:919
> #11 0x00007ffab00830ad in QX11PaintEngine::updateBrush (this=0x710950, brush=@0x7fffb935b5e0, origin=@0x7fffb935b490)
>     at painting/qpaintengine_x11.cpp:1252
> #12 0x00007ffab0083d65 in QX11PaintEngine::updateState (this=0x710950, state=@0x2be9120)
>     at painting/qpaintengine_x11.cpp:985
> #13 0x00007ffaaffd248f in QPainterPrivate::updateState (this=0x2be8910, newState=0x2be9120) at painting/qpainter.cpp:891
> #14 0x00007ffaaffdb73e in QPainter::drawRects (this=0x7fffb935ee90, rects=0x7fffb935b9b0, rectCount=1)
>     at painting/qpainter.cpp:2956
> #15 0x00007ffaafef916e in QPainter::drawRect (this=0x7fffb935ee90, r=@0x7fffb935b9b0)
>     at ../../include/QtGui/../../src/gui/painting/qpainter.h:593
> #16 0x00007ffaaffdbcd4 in QPainter::fillRect (this=0x7fffb935ee90, r=@0x7fffb935b9b0, brush=@0x7fffb935bcd0)
>     at painting/qpainter.cpp:5757
> #17 0x00007ffaaffc9fd4 in QPainter::fillRect (this=0x7fffb935ee90, x=30, y=28, w=1, h=7, b=@0x7fffb935bcd0)
>     at ../../include/QtGui/../../src/gui/painting/qpainter.h:716
> #18 0x00007ffab02435fe in QWindowsStyle::drawPrimitive (this=0x6b8830, pe=QStyle::PE_IndicatorBranch,
>     opt=0x7fffb935e260, p=0x7fffb935ee90, w=0x766e50) at styles/qwindowsstyle.cpp:1617
> #19 0x00007ffab0233e1b in QCleanlooksStyle::drawPrimitive (this=0x6b8830, elem=QStyle::PE_IndicatorBranch,
>     option=0x7fffb935e260, painter=0x7fffb935ee90, widget=0x766e50) at styles/qcleanlooksstyle.cpp:1374
> #20 0x00007ffab01bff49 in QStyleSheetStyle::drawPrimitive (this=0x6deee0, pe=QStyle::PE_IndicatorBranch,
>     opt=0x7fffb935e5f0, p=0x7fffb935ee90, w=0x766e50) at styles/qstylesheetstyle.cpp:4138
> #21 0x00007ffab0444da1 in QTreeView::drawBranches (this=0x766e50, painter=0x7fffb935ee90, rect=@0x7fffb935ea70,
>     index=@0x741b10) at itemviews/qtreeview.cpp:1668
> #22 0x00007ffab0445fc2 in QTreeView::drawRow (this=0x766e50, painter=0x7fffb935ee90, option=@0x7fffb935ec90,
>     index=@0x741b10) at itemviews/qtreeview.cpp:1553
> #23 0x00007ffab04469b7 in QTreeView::drawTree (this=0x766e50, painter=0x7fffb935ee90, region=@0x7fffb935fd18)
>     at itemviews/qtreeview.cpp:1345
> #24 0x00007ffab0447607 in QTreeView::paintEvent (this=0x766e50, event=0x7fffb935fcf0) at itemviews/qtreeview.cpp:1255
> #25 0x00007ffaaff08e0e in QWidget::event (this=0x766e50, event=0x7fffb935fcf0) at kernel/qwidget.cpp:6988
> #26 0x00007ffab02b1a21 in QFrame::event (this=0x766e50, e=0x7fffb935fcf0) at widgets/qframe.cpp:657
> #27 0x00007ffab03534b4 in QAbstractScrollArea::viewportEvent (this=0x766e50, e=0x7fffb935fcf0)
>     at widgets/qabstractscrollarea.cpp:938
> #28 0x00007ffab0409429 in QAbstractItemView::viewportEvent (this=0x766e50, event=0x7fffb935fcf0)
>     at itemviews/qabstractitemview.cpp:1423
> #29 0x00007ffab0447ab1 in QTreeView::viewportEvent (this=0x766e50, event=0x7fffb935fcf0) at itemviews/qtreeview.cpp:1240
> ---Type <return> to continue, or q <return> to quit---
> #30 0x00007ffab03562b8 in QAbstractScrollAreaPrivate::viewportEvent (this=0x7a4800, event=0x7fffb935fcf0)
>     at widgets/qabstractscrollarea_p.h:102
> #31 0x00007ffab03562f8 in QAbstractScrollAreaFilter::eventFilter (this=0x6f84d0, o=0x70c270, e=0x7fffb935fcf0)
>     at widgets/qabstractscrollarea_p.h:113
> #32 0x00007ffaae3625e3 in QCoreApplicationPrivate::sendThroughObjectEventFilters (this=0x678210, receiver=0x70c270,
>     event=0x7fffb935fcf0) at kernel/qcoreapplication.cpp:693
> #33 0x00007ffaafea23be in QApplicationPrivate::notify_helper (this=0x678210, receiver=0x70c270, e=0x7fffb935fcf0)
>     at kernel/qapplication.cpp:3731
> #34 0x00007ffaafea41b1 in QApplication::notify (this=0x7fffb9361580, receiver=0x70c270, e=0x7fffb935fcf0)
>     at kernel/qapplication.cpp:3702
> #35 0x00007ffaae364763 in QCoreApplication::notifyInternal (this=0x7fffb9361580, receiver=0x70c270,
>     event=0x7fffb935fcf0) at kernel/qcoreapplication.cpp:586
> #36 0x00007ffaafeb0291 in QCoreApplication::sendSpontaneousEvent (receiver=0x70c270, event=0x7fffb935fcf0)
>     at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:218
> #37 0x00007ffaaff1745d in qt_sendSpontaneousEvent (receiver=0x70c270, event=0x7fffb935fcf0)
>     at kernel/qapplication_x11.cpp:4637
> #38 0x00007ffaaff1096a in QWidgetPrivate::drawWidget (this=0x7551d0, pdev=0x70d2e8, rgn=@0x7fffb935ffa0,
>     offset=@0x7fffb935ff60, flags=4, sharedPainter=0x2be71a0) at kernel/qwidget.cpp:4421
> #39 0x00007ffaaff11215 in QWidgetPrivate::paintSiblingsRecursive (this=0x7a4800, pdev=0x70d2e8,
>     siblings=@0x7fffb9360170, index=1, rgn=@0x7fffb9360340, offset=@0x7fffb9360300, flags=4, sharedPainter=0x2be71a0)
>     at kernel/qwidget.cpp:4519
> #40 0x00007ffaaff10dc3 in QWidgetPrivate::drawWidget (this=0x7a4800, pdev=0x70d2e8, rgn=@0x7fffb9360340,
>     offset=@0x7fffb9360300, flags=4, sharedPainter=0x2be71a0) at kernel/qwidget.cpp:4462
> #41 0x00007ffaaff11215 in QWidgetPrivate::paintSiblingsRecursive (this=0x6df300, pdev=0x70d2e8,
>     siblings=@0x7fffb9360510, index=10, rgn=@0x7fffb9360790, offset=@0x70d358, flags=4, sharedPainter=0x2be71a0)
>     at kernel/qwidget.cpp:4519
> #42 0x00007ffaaff10dc3 in QWidgetPrivate::drawWidget (this=0x6df300, pdev=0x70d2e8, rgn=@0x7fffb9360790,
>     offset=@0x70d358, flags=5, sharedPainter=0x2be71a0) at kernel/qwidget.cpp:4462
> #43 0x00007ffab009ccd1 in QWidgetBackingStore::cleanRegion (this=0x70d340, rgn=@0x7fffb9360810, widget=0x6debd0,
>     recursiveCopyToScreen=true) at painting/qbackingstore.cpp:1041
> #44 0x00007ffab009d644 in qt_syncBackingStore (widget=0x6debd0) at painting/qbackingstore.cpp:315
> #45 0x00007ffaaff09456 in QWidget::event (this=0x6debd0, event=0x2becb00) at kernel/qwidget.cpp:7132
> #46 0x00007ffab02d20fe in QMainWindow::event (this=0x6debd0, event=0x2becb00) at widgets/qmainwindow.cpp:1252
> #47 0x00007ffaafea23e3 in QApplicationPrivate::notify_helper (this=0x678210, receiver=0x6debd0, e=0x2becb00)
>     at kernel/qapplication.cpp:3735
> #48 0x00007ffaafea41b1 in QApplication::notify (this=0x7fffb9361580, receiver=0x6debd0, e=0x2becb00)
>     at kernel/qapplication.cpp:3702
> #49 0x00007ffaae364763 in QCoreApplication::notifyInternal (this=0x7fffb9361580, receiver=0x6debd0, event=0x2becb00)
>     at kernel/qcoreapplication.cpp:586
> #50 0x00007ffaafe9f2db in QCoreApplication::sendEvent (receiver=0x6debd0, event=0x2becb00)
>     at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:215
> #51 0x00007ffaae364d73 in QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=0, data=0x665b50)
>     at kernel/qcoreapplication.cpp:1191
> #52 0x00007ffaae365038 in QCoreApplication::sendPostedEvents (receiver=0x0, event_type=0)
>     at kernel/qcoreapplication.cpp:1084
> ---Type <return> to continue, or q <return> to quit---
> #53 0x00007ffaaff5a94d in QCoreApplication::sendPostedEvents ()
>     at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:220
> #54 0x00007ffaae399cf9 in postEventSourceDispatch (s=0x685050) at kernel/qeventdispatcher_glib.cpp:211
> #55 0x00007ffaad944222 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
> #56 0x00007ffaad9474d6 in ?? () from /usr/lib/libglib-2.0.so.0
> #57 0x00007ffaad94796f in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
> #58 0x00007ffaae398e92 in QEventDispatcherGlib::processEvents (this=0x681c10, flags=@0x7fffb93613c0)
>     at kernel/qeventdispatcher_glib.cpp:325
> #59 0x00007ffaaff58e63 in QGuiEventDispatcherGlib::processEvents (this=0x681c10, flags=@0x7fffb9361420)
>     at kernel/qguieventdispatcher_glib.cpp:204
> #60 0x00007ffaae361175 in QEventLoop::processEvents (this=0x7fffb93614d0, flags=@0x7fffb9361490)
>     at kernel/qeventloop.cpp:146
> #61 0x00007ffaae361308 in QEventLoop::exec (this=0x7fffb93614d0, flags=@0x7fffb93614f0) at kernel/qeventloop.cpp:197
> #62 0x00007ffaae365145 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:838
> #63 0x00007ffaafea2144 in QApplication::exec () at kernel/qapplication.cpp:3267
> #64 0x0000000000427bf1 in main (argc=2, argv=0x7fffb93617a8) at main.cpp:96

--
 [ signature omitted ]