Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-42875

Custom image provider crashes when query is cancelled

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.3.0
    • None
    • Ubuntu 14.10, qtdeclarative5-qtquick2-plugin version 5.3.0-3ubuntu13 on x86_64-linux-gnu.

    Description

      I am writing an app with a custom image provider (that inherits QQuickImageProvider) that queries the network.

      Since QNAM’s API is asynchronous, and QQuickImageProvider::requestImage() is expected to synchronously return the image, my implementation issues a network request and waits for the reply by instantiating a local event loop whose quit() slot is connected to the reply’s finished() signal.

      This works well under normal conditions, but if I stress the provider a bit by issuing and cancelling requests quickly, I can get it to crash pretty consistently with the following stacktrace:

      #0  QCoreApplication::postEvent (receiver=0x93bab0, event=0x7fffc400acc0, priority=0)
          at kernel/qcoreapplication.cpp:1284
      #1  0x00007ffff791945e in QQuickPixmapReader::processJob (this=0x7b7ba0, runningJob=0x93bab0, url=..., requestSize=...)
          at util/qquickpixmapcache.cpp:563
      #2  0x00007ffff7919f84 in QQuickPixmapReader::processJobs (this=0x7b7ba0) at util/qquickpixmapcache.cpp:526
      #3  0x00007ffff791a2bd in QQuickPixmapReaderThreadObject::event (this=<optimized out>, e=<optimized out>)
          at util/qquickpixmapcache.cpp:480
      #4  0x00007ffff6afd16c in QApplicationPrivate::notify_helper (this=0x616020, receiver=0x7fffc40013a0, e=0xaf3e90)
          at kernel/qapplication.cpp:3504
      #5  0x00007ffff6b0241e in QApplication::notify (this=0x7fffffffdc40, receiver=0x7fffc40013a0, e=0xaf3e90)
          at kernel/qapplication.cpp:3287
      #6  0x00007ffff5ad281b in QCoreApplication::notifyInternal (this=0x7fffffffdc40, receiver=0x7fffc40013a0, 
          event=event@entry=0xaf3e90) at kernel/qcoreapplication.cpp:935
      #7  0x00007ffff5ad47e3 in sendEvent (event=0xaf3e90, receiver=<optimized out>)
          at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:237
      #8  QCoreApplicationPrivate::sendPostedEvents (receiver=receiver@entry=0x0, event_type=event_type@entry=0, 
          data=0x7b7cb0) at kernel/qcoreapplication.cpp:1539
      #9  0x00007ffff5ad4de8 in QCoreApplication::sendPostedEvents (receiver=receiver@entry=0x0, 
          event_type=event_type@entry=0) at kernel/qcoreapplication.cpp:1397
      #10 0x00007ffff5b29a63 in postEventSourceDispatch (s=0x7fffc40012d0) at kernel/qeventdispatcher_glib.cpp:279
      #11 0x00007ffff423bc5d in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
      #12 0x00007ffff423bf48 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
      #13 0x00007ffff423bffc in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
      #14 0x00007ffff5b29e57 in QEventDispatcherGlib::processEvents (this=0x7fffc40008c0, flags=...)
          at kernel/qeventdispatcher_glib.cpp:426
      #15 0x00007ffff5ad0042 in QEventLoop::exec (this=0x7fffd1a2a680, flags=...) at kernel/qeventloop.cpp:212
      #16 0x0000000000403ade in downloadImage(QUrl const&) ()
      

      The issue seems to happen when processing events in the local event loop while waiting for the network reply, when the image request has been cancelled.

      Not sure whether this is an actual bug in Qt or whether my code is incorrect (in which case I would appreciate if someone could enlighten me).

      I’m attaching a simple standalone reproducer. Loading icons quickly in succession almost always results in a crash.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              aalpert Alan Alpert
              osomon Olivier Tilloy
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes