Results 1 to 6 of 6

Thread: Access violation while alt-tabbing from an actively updated plot widget

  1. #1
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Access violation while alt-tabbing from an actively updated plot widget

    Hello,

    I'm using Qt 4.5.1 and qwt 5.2.0 on Windows XP (Eclipse, g++). I have a graphing widget which inherits from QwtPlot. This is used to display often updated measurement data which is contained in a single curve. The graphing widget itself is refreshed with update() in the main thread using a timer, and the actual curve data is set from a measurement thread. Access to these functions is behind a single mutex. The plot also uses QwtPlotzoomer. The application seems to work fine when I don't disturb it while the plot is being updated, but I'm bumping to an access violation somewhat randomly if I alt-tab back on the application during a wrong time.

    If I run the application under gdb, I also see the following warnings when I alt-tab in/out:
    Qt Code:
    1. warning: QWidget::repaint: Recursive repaint detected
    2.  
    3. warning: QPainter::begin: Paint device returned engine == 0, type: 1
    To copy to clipboard, switch view to plain text mode 

    I have no repaint()s in the application itself, so they are performed somewhere within q(w)t. Also autoReplot is turned off.

    The backtrace from Dr. Mingw is contained in the following post (character limit). gdb backtrace is not included due to some symbol-resolving problem.

  2. #2
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access violation while alt-tabbing from an actively updated plot widget

    Qt Code:
    1. meas.exe caused an Access Violation at location 1009a3a5 in module qwt5.dll Reading from location 09230028.
    2.  
    3. Registers:
    4. eax=09230020 ebx=0022bc40 ecx=6a307128 edx=100afe38 esi=0000000a edi=0022c4dc
    5. eip=1009a3a5 esp=0022b8d0 ebp=0022b8e8 iopl=0 nv up ei pl nz na pe nc
    6. cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
    7.  
    8. Call stack:
    9. AddrPC AddrReturn AddrFrame AddrStack Params
    10. 1009A3A5 100278BD 0022B8E8 0022B8D0 06A09EF8 0001068F 0022B908 10090B89
    11. 1009A3A5 qwt5.dll:1009A3A5 QVector<double>::operator[] qvector.h:333
    12. ...
    13. template <typename T>
    14. inline const T &QVector<T>::operator[](int i) const
    15. > { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::operator[]", "index out of range");
    16. return d->array[i]; }
    17. template <typename T>
    18. ...
    19.  
    20. 100278BD 10090B89 0022B8F8 0022B8D0 06A09EF0 0001068F 0022BA18 10034A59
    21. 100278BD qwt5.dll:100278BD QwtArrayData::y qwt_data.cpp:210
    22. ...
    23. double QwtArrayData::y(size_t i) const
    24. {
    25. > return d_y[int(i)];
    26. }
    27.  
    28. ...
    29.  
    30. 10090B89 10034A59 0022B908 0022B8D0 069F2850 0001068F 3F019EB8 000001D1
    31. 10090B89 qwt5.dll:10090B89E:\projects\meas\debug\qwt5.dll: No symbol found
    32. _ZNK12QwtPlotCurve1yEi
    33. 10034A59 1003435D 0022BA18 0022B8D0 069F2850 0022BDE0 0022BCA0 0022BC40
    34. 10034A59 qwt5.dll:10034A59 QwtPlotCurve::drawLines qwt_plot_curve.cpp:815
    35. ...
    36. {
    37. int xi = xMap.transform(x(i));
    38. > int yi = yMap.transform(y(i));
    39.  
    40. polyline.setPoint(i - from, xi, yi);
    41. ...
    42.  
    43. 1003435D 10034230 0022BA48 0022B8D0 069F2850 0022BDE0 00000001 0022BCA0
    44. 1003435D qwt5.dll:1003435D QwtPlotCurve::drawCurve qwt_plot_curve.cpp:685
    45. ...
    46. }
    47. drawLines(painter, xMap, yMap, from, to);
    48. > break;
    49. case Sticks:
    50. drawSticks(painter, xMap, yMap, from, to);
    51. ...
    52.  
    53. 10034230 10033A03 0022BAD8 0022B8D0 069F2850 0022BDE0 0022BCA0 0022BC40
    54. 10034230 qwt5.dll:10034230 QwtPlotCurve::draw qwt_plot_curve.cpp:648
    55. ...
    56.  
    57. drawCurve(painter, d_data->style, xMap, yMap, from, to);
    58. > painter->restore();
    59.  
    60. if (d_data->symbol->style() != QwtSymbol::NoSymbol)
    61. ...
    62.  
    63. 10033A03 1002DF98 0022BAF8 0022B8D0 069F2850 0022BDE0 0022BCA0 0022BC40
    64. 10033A03 qwt5.dll:10033A03 QwtPlotCurve::draw qwt_plot_curve.cpp:521
    65. ...
    66. {
    67. draw(painter, xMap, yMap, 0, -1);
    68. > }
    69.  
    70. /*!
    71. ...
    72.  
    73. 1002DF98 1002DCD2 0022BB68 0022B8D0 069E7D40 0022BDE0 0022BC10 0022BC40
    74. 1002DF98 qwt5.dll:1002DF98 QwtPlot::drawItems qwt_plot.cpp:580
    75. ...
    76. rect);
    77.  
    78. > painter->restore();
    79. }
    80. }
    81. ...
    82.  
    83. 1002DCD2 10047690 0022BD18 0022B8D0 069E7D40 0022BDE0 C0000000 00000000
    84. 1002DCD2 qwt5.dll:1002DCD2 QwtPlot::drawCanvas qwt_plot.cpp:540
    85. ...
    86. maps[axisId] = canvasMap(axisId);
    87.  
    88. > drawItems(painter,
    89. d_data->canvas->contentsRect(), maps, QwtPlotPrintFilter());
    90. }
    91. ...
    92.  
    93. 10047690 1004728C 0022BE18 0022B8D0 069F2278 0022BF30 00000000 FFFFFFFF
    94. 10047690 qwt5.dll:10047690 QwtPlotCanvas::drawCanvas qwt_plot_canvas.cpp:337
    95. ...
    96. ((QwtPlot *)parent())->drawCanvas(&cachePainter);
    97.  
    98. > cachePainter.end();
    99.  
    100. painter->drawPixmap(contentsRect(), *d_data->cache);
    101. ...
    102.  
    103. 1004728C 100470E5 0022BE88 0022B8D0 069F2278 0022BF30 00000001 0000004D
    104. 1004728C qwt5.dll:1004728C QwtPlotCanvas::drawContents qwt_plot_canvas.cpp:275
    105. ...
    106. drawCanvas(painter);
    107.  
    108. > plot->setAutoReplot(doAutoReplot);
    109. }
    110.  
    111. ...
    112.  
    113. 100470E5 00E3888D 0022BF58 0022B8D0 069F2278 0022C5F0 0022BFC8 00DEA420
    114. 100470E5 qwt5.dll:100470E5 QwtPlotCanvas::paintEvent qwt_plot_canvas.cpp:252
    115. ...
    116. #endif
    117.  
    118. > if ( d_data->paintAttributes & PaintPacked )
    119. setSystemBackground(false);
    120. }
    121. ...
    122.  
    123. 00E3888D 0127F743 0022C0C8 0022B8D0 069F2278 0022C5F0 00000000 00000001
    124. 00E3888D QtGuid4.dll:00E3888D
    125. adjusting sections from 0x68f40000 to 0x00dc0000, 0x97e80000
    126. E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    127.   _ZN7QWidget5eventEP6QEvent
    128. 0127F743 00DD85CD 0022C0E8 0022B8D0 069F2278 0022C5F0 0022C5F0 05B14CC0
    129. 0127F743 QtGuid4.dll:0127F743E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    130.   _ZN6QFrame5eventEP6QEvent
    131. 00DD85CD 00DD8444 0022C118 0022B8D0 05B14DE8 069F2278 0022C5F0 7C9100B8
    132. 00DD85CD QtGuid4.dll:00DD85CDE:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    133.   _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent
    134. 00DD8444 6A242200 0022C468 0022B8D0 0022FDE0 069F2278 0022C5F0 00000312
    135. 00DD8444 QtGuid4.dll:00DD8444E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    136.   _ZN12QApplication6notifyEP7QObjectP6QEvent
    137. 6A242200 015BDF58 0022C508 0022B8D0 0022FDE0 069F2278 0022C5F0 0000004D
    138. 6A242200 QtCored4.dll:6A242200 QCoreApplication::notifyInternal qcoreapplication.cpp:610
    139. ...
    140. bool returnValue;
    141. try {
    142. > returnValue = notify(receiver, event);
    143. } catch(...) {
    144. --threadData->loopLevel;
    145. ...
    146.  
    147. 015BDF58 00E2FD10 0022C528 0022B8D0 069F2278 0022C5F0 0022C790 0000000C
    148. 015BDF58 QtGuid4.dll:015BDF58E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    149.   _ZN16QAccessibleEvent8setValueERK7QString
    150. 00E2FD10 00FF168A 0022C6C8 0022B8D0 069F2298 06A1C650 0022C8A0 0022C790
    151. 00E2FD10 QtGuid4.dll:00E2FD10E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    152.   _ZN14QWidgetPrivate10drawWidgetEP12QPaintDeviceRK7QRegionRK6QPointiP8QPainterP19QWidgetBackingStore
    153. 00FF168A 00E2525E 0022C928 0022B8D0 06A0D128 0000000A 0022C958 01563590
    154. 00FF168A QtGuid4.dll:00FF168AE:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    155.   _ZN14QWidgetPrivate10scrollRectERK5QRectii
    156. 00E2525E 00E38F79 0022C9A8 0022B8D0 05B185D0 6A2A51D4 6A302228 0022C9E0
    157. 00E2525E QtGuid4.dll:00E2525EE:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    158.   _ZN14QWidgetPrivate16syncBackingStoreEv
    159. 00E38F79 012A62F0 0022CB18 0022B8D0 0022F250 06A095F0 00E040A9 00000000
    160. 00E38F79 QtGuid4.dll:00E38F79E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    161.   _ZN7QWidget5eventEP6QEvent
    162. 012A62F0 00DD85CD 0022CC08 0022B8D0 0022F250 06A095F0 06A095F0 05B14CC0
    163. 012A62F0 QtGuid4.dll:012A62F0E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    164.   _ZN11QMainWindow5eventEP6QEvent
    165. 00DD85CD 00DD8444 0022CC38 0022B8D0 05B14DE8 0022F250 06A095F0 6A2F7B69
    166. 00DD85CD QtGuid4.dll:00DD85CDE:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    167.   _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent
    168. 00DD8444 6A242200 0022CF88 0022B8D0 0022FDE0 0022F250 06A095F0 6A2B5729
    169. 00DD8444 QtGuid4.dll:00DD8444E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    170.   _ZN12QApplication6notifyEP7QObjectP6QEvent
    171. 6A242200 6A2B79FB 0022D028 0022B8D0 0022FDE0 0022F250 06A095F0 6A2B2CFC
    172. 6A242200 QtCored4.dll:6A242200 QCoreApplication::notifyInternal qcoreapplication.cpp:610
    173. ...
    174. bool returnValue;
    175. try {
    176. > returnValue = notify(receiver, event);
    177. } catch(...) {
    178. --threadData->loopLevel;
    179. ...
    180.  
    181. 6A2B79FB 6A24339B 0022D048 0022B8D0 0022F250 06A095F0 7FFDD000 0022D0EC
    182. 6A2B79FB QtCored4.dll:6A2B79FBE:\soft\Qt\4.5.1\bin\QtCored4.dll: No symbol found
    183.   _ZN16QCoreApplication9sendEventEP7QObjectP6QEvent
    184. 6A24339B 6A2731BE 0022D148 0022B8D0 00000000 00000000 05B145F8 000000FF
    185. 6A24339B QtCored4.dll:6A24339B QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp:1247
    186. ...
    187. #else
    188. try {
    189. > QCoreApplication::sendEvent(r, e);
    190. } catch (...) {
    191. delete e;
    192. ...
    193.  
    194. 6A2731BE 00E4715C 0022EFA8 0022B8D0 05B14C28 0022EFD0 05B145F8 6A17A207
    195. 6A2731BE QtCored4.dll:6A2731BE QEventDispatcherWin32::processEvents qeventdispatcher_win.cpp:681
    196. ...
    197. QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData);
    198.  
    199. > DWORD waitRet = 0;
    200. HANDLE pHandles[MAXIMUM_WAIT_OBJECTS - 1];
    201. QVarLengthArray<MSG> processedTimers;
    202. ...
    203.  
    204. 00E4715C 6A23F38E 0022EFE8 0022B8D0 05B14C28 0022F010 00000010 00000002
    205. 00E4715C QtGuid4.dll:00E4715CE:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    206.   _Z25qWinProcessConfigRequestsv
    207. 6A23F38E 6A23F510 0022F038 0022B8D0 0022F170 0022F0B0 00000020 6A25770E
    208. 6A23F38E QtCored4.dll:6A23F38E QEventLoop::processEvents qeventloop.cpp:149
    209. ...
    210. if (flags & DeferredDeletion)
    211. QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
    212. > return d->threadData->eventDispatcher->processEvents(flags);
    213. }
    214.  
    215. ...
    216.  
    217. 6A23F510 6A2428D1 0022F0E8 0022B8D0 0022F170 0022F150 00000000 00000000
    218. 6A23F510 QtCored4.dll:6A23F510 QEventLoop::exec qeventloop.cpp:200
    219. ...
    220. try {
    221. while (!d->exit)
    222. > processEvents(flags | WaitForMoreEvents | EventLoopExec);
    223. } catch (...) {
    224. qWarning("Qt has caught an exception thrown from an event handler. Throwing\n"
    225. ...
    226.  
    227. 6A2428D1 00DD6364 0022F1A8 0022B8D0 0022FDE0 00000001 0022FE08 0040F703
    228. 6A2428D1 QtCored4.dll:6A2428D1 QCoreApplication::exec qcoreapplication.cpp:888
    229. ...
    230. self->d_func()->in_exec = true;
    231. self->d_func()->aboutToQuitEmitted = false;
    232. > int returnCode = eventLoop.exec();
    233. threadData->quitNow = false;
    234. if (self) {
    235. ...
    236.  
    237. 00DD6364 0040F703 0022F1B8 0022B8D0 0022F250 0048B4C4 0022F264 00040501
    238. 00DD6364 QtGuid4.dll:00DD6364E:\soft\Qt\4.5.1\bin\QtGuid4.dll: No symbol found
    239.   _ZN12QApplication4execEv
    240. 0040F703 00432FFD 0022FE08 0022B8D0 00000001 05B14DC0 05B14D38 0000000A
    241. 0040F703 meas.exe:0040F703 qMain main.cpp:30
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access violation while alt-tabbing from an actively updated plot widget

    Some possibly relevant code snippets:

    Qt Code:
    1. void Graph::paintEvent(QPaintEvent *event) {
    2.  
    3. if (mutex.tryLock()) {
    4. replot();
    5. QwtPlot::paintEvent(event);
    6.  
    7. mutex.unlock();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Graph::Graph(QWidget *parent): QwtPlot(parent) {
    2. mutex.lock();
    3.  
    4. QTimer *timer = new QTimer(this);
    5. connect(timer, SIGNAL(timeout()), this, SLOT(refresh()));
    6. timer->start(GRAPH_REDRAW_TIMER);
    7.  
    8. setCanvasBackground(QColor(29, 100, 141));
    9. setFrameStyle(QFrame::NoFrame);
    10. setLineWidth(0);
    11. setCanvasLineWidth(2);
    12. plotLayout()->setAlignCanvasToScales(true);
    13.  
    14. QwtPlotGrid *grid = new QwtPlotGrid;
    15. grid->setMajPen(QPen(Qt::gray, 0, Qt::DashLine));
    16. grid->setMinPen(QPen(Qt::gray, 0, Qt::DotLine));
    17. grid->enableXMin(true);
    18. grid->attach(this);
    19.  
    20. plotLayout()->setAlignCanvasToScales(true);
    21.  
    22. crv = new QwtPlotCurve();
    23. crv->setPen(QColor(Qt::white));
    24. crv->setStyle(QwtPlotCurve::Lines);
    25. crv->attach(this);
    26.  
    27. zoomer = new QwtPlotZoomer(canvas(), true);
    28. zoomer->setRubberBandPen(QPen(Qt::white, 2, Qt::DotLine));
    29. zoomer->setTrackerPen(QPen(Qt::white));
    30.  
    31. connect(zoomer, SIGNAL(zoomed(const QwtDoubleRect &)),
    32. this, SLOT(catchZoomed(const QwtDoubleRect &)));
    33. //canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
    34. zoomer->setZoomBase();
    35.  
    36. setAutoReplot(false);
    37. mutex.unlock();
    38. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Graph::refresh() {
    2. mutex.lock();
    3. // qDebug("refresh here");
    4. update();
    5. //replot();
    6. mutex.unlock();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Graph::catchZoomed(const QwtDoubleRect &rect) {
    2. mutex.lock();
    3. if (zoomer->zoomRectIndex() == 0) {
    4. setAxisAutoScale(QwtPlot::yLeft);
    5. setAxisAutoScale(QwtPlot::xBottom);
    6. zoomer->setZoomBase();
    7. }
    8. mutex.unlock();
    9. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Access violation while alt-tabbing from an actively updated plot widget

    Quote Originally Posted by dumdidum View Post
    Some possibly relevant code snippets:
    The crash happens, when accessing the curve data. So the relevant code is how you assign the points to your curve.

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    dumdidum (2nd November 2009)

  6. #5
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access violation while alt-tabbing from an actively updated plot widget

    Quote Originally Posted by Uwe View Post
    The crash happens, when accessing the curve data. So the relevant code is how you assign the points to your curve.

    Uwe
    Qt Code:
    1. void Graph::setXY(double *x, double *y, int size) {
    2. mutex.lock();
    3. crv->setData(x, y, size);
    4. mutex.unlock();
    5. }
    To copy to clipboard, switch view to plain text mode 

    The plot itself lives in the main thread, but this function is called from another thread.

  7. #6
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access violation while alt-tabbing from an actively updated plot widget

    Hurr, yeah. I get your hint now that I read the code and documents for a while: this is a threading problem. I replaced the direct function call from another thread with a signal-slot connection, which makes sure that the setData() call is handled in the appropriate thread.

    Many thanks for your guidance!

    Quote Originally Posted by http://doc.trolltech.com/4.2/threads.html#qobject-reentrancy
    Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.
    Last edited by dumdidum; 17th June 2009 at 14:05.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.