Results 1 to 6 of 6

Thread: non GUI thread use

  1. #1
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default non GUI thread use

    I make an unusual use of Qt: I've developped a Qt based library and I want to provide its services to Java too using a JNI (in addition to a standard C++ API).
    Here is how it currently works:
    • when the library is initalized in the context of a stand-alone application, it creates a QGraphicsScene which is rendered in a QGraphicsView
    • when the library is initalized in a Java context, it creates a QGraphicsScene which is rendered in a QImage at Java client request

    In both cases, I create a QApplication but in the Java context, I don't call QApplication::exec().
    The QGraphicsScene is modified by the time task of a QTimer.
    In the Java context, a QMutex ensures that the time task and the Java client request to get the scene bitmap data don't collide.

    It basically works but it also crashes randomly and here is my current investigation state.
    First of all, I've replaced the QPixmap with QImage since the final QImage rendering is made outside a GUI thread (and Qt complained about that).
    Now there is a single remaining warning at client startup:
    "QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread"

    Here is the code of the Java context rendering scheme:

    Qt Code:
    1. QImage image (w, h, QImage::Format_ARGB32_Premultiplied);
    2. QPainter painter(&image);
    3. painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
    4. fScene->render(&painter);
    5. painter.end();
    To copy to clipboard, switch view to plain text mode 
    Note that it doesn't crash when I comment out the 'render' call.

    I don't get anymore warning from Qt and the developer documentation only talks about QWidget that should not be used in a non GUI thread. Most of the crashes occur when modifying a QGraphicsSceneBspTreeIndex (or QGraphicsSceneBspTreeIndexPrivate) object. It looks like there are remaining unsafe operations called.

    Any help would be greatly appreciated.

  2. #2
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: non GUI thread use

    I guess the question and the context are maybe not familiar to this list users.
    If nobody has an answer, maybe someone knows a better place to ask.
    Best,

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: non GUI thread use

    I would rather say your post isn't clear at what you are really doing. A minimal compilable example reproducing the problem might help. And if not then even just a backtrace of the crash could be helpful.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: non GUI thread use

    Quote Originally Posted by wysota View Post
    I would rather say your post isn't clear at what you are really doing. A minimal compilable example reproducing the problem might help. And if not then even just a backtrace of the crash could be helpful.
    It's quite difficult to make a minimal compilable example since it involves a Qt based shared library, a JNI shared library and a Java virtual machine. I'll try to make one. Concerning the backtrace, here are two of them:

    the first one corresponds to a timer task, i.e. it should not correspond to a JNI call
    Qt Code:
    1. Thread 0 Crashed: Dispatch queue: com.apple.main-thread
    2. 0 QtGui 0x00000001354fbf82 QList<QGraphicsItem*>::detach_helper_grow(int, int) + 146
    3. 1 QtGui 0x000000013566a484 QGraphicsSceneInsertItemBspTreeVisitor::visit(QList<QGraphicsItem*>*) + 36
    4. 2 QtGui 0x0000000135668ab2 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 290
    5. 3 QtGui 0x0000000135668a13 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 131
    6. 4 QtGui 0x0000000135668ab2 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 290
    7. 5 QtGui 0x0000000135668a13 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 131
    8. 6 QtGui 0x0000000135668ab2 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 290
    9. 7 QtGui 0x0000000135668a13 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 131
    10. 8 QtGui 0x0000000135668ab2 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 290
    11. 9 QtGui 0x0000000135668a13 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 131
    12. 10 QtGui 0x0000000135668ab2 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 290
    13. 11 QtGui 0x0000000135668a13 QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor*, QRectF const&, int) const + 131
    14. 12 QtGui 0x000000013566bde5 QGraphicsSceneBspTreeIndexPrivate::_q_updateIndex() + 1013
    15. 13 QtGui 0x000000013566bef6 QGraphicsSceneBspTreeIndex::event(QEvent*) + 102
    16. 14 QtGui 0x0000000135081ddd QApplicationPrivate::notify_helper(QObject*, QEvent*) + 189
    17. 15 QtGui 0x0000000135088dfe QApplication::notify(QObject*, QEvent*) + 2094
    18. 16 QtCore 0x00000001322a2dec QCoreApplication::notifyInternal(QObject*, QEvent*) + 124
    19. 17 QtGui 0x0000000135081e7c qt_sendSpontaneousEvent(QObject*, QEvent*) + 44
    20. 18 QtGui 0x000000013503b79c QEventDispatcherMacPrivate::activateTimer(__CFRunLoopTimer*, void*) + 188
    21. 19 com.apple.CoreFoundation 0x00007fff86484be8 __CFRunLoopRun + 6488
    22. 20 com.apple.CoreFoundation 0x00007fff86482dbf CFRunLoopRunSpecific + 575
    23. 21 com.apple.HIToolbox 0x00007fff8611e91a RunCurrentEventLoopInMode + 333
    24. 22 com.apple.HIToolbox 0x00007fff8611e71f ReceiveNextEventCommon + 310
    25. 23 com.apple.HIToolbox 0x00007fff8611e5d8 BlockUntilNextEventMatchingListInMode + 59
    26. 24 com.apple.AppKit 0x00007fff870ebe64 _DPSNextEvent + 718
    27. 25 com.apple.AppKit 0x00007fff870eb7a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
    28. 26 com.apple.AppKit 0x00007fff870b148b -[NSApplication run] + 395
    29. 27 libawt.jnilib 0x000000011a940a04 +[AWTStarter startAWT:] + 1286
    30. 28 libawt.jnilib 0x000000011a904625 -[CPerformer perform] + 93
    31. 29 com.apple.Foundation 0x00007fff86d5344f __NSThreadPerformPerform + 219
    32. 30 com.apple.CoreFoundation 0x00007fff86485401 __CFRunLoopDoSources0 + 1361
    33. 31 com.apple.CoreFoundation 0x00007fff864835f9 __CFRunLoopRun + 873
    34. 32 com.apple.CoreFoundation 0x00007fff86482dbf CFRunLoopRunSpecific + 575
    To copy to clipboard, switch view to plain text mode 

    the second one clearly corresponds to a JNI call

    Qt Code:
    1. Thread 28 Crashed: Java: AWT-EventQueue-0
    2. 0 libSystem.B.dylib 0x00007fffffe00f46 __memcpy + 1958
    3. 1 QtCore 0x0000000132a5fbbc QListData::remove(int) + 140
    4. 2 QtCore 0x0000000132a6011e QListData::erase(void**) + 46
    5. 3 QtGui 0x0000000135a95a9d QGraphicsSceneBspTreeIndexPrivate::_q_updateIndex() + 173
    6. 4 QtGui 0x0000000135a95f1b QGraphicsSceneBspTreeIndexPrivate::_q_updateSortCache() + 27
    7. 5 QtGui 0x0000000135a962ff QGraphicsSceneBspTreeIndexPrivate::estimateItems(QRectF const&, Qt::SortOrder, bool) + 271
    8. 6 QtGui 0x0000000135a963fb QGraphicsSceneBspTreeIndex::estimateTopLevelItems(QRectF const&, Qt::SortOrder) const + 27
    9. 7 QtGui 0x0000000135a9a17b QGraphicsSceneIndex::items(QRectF const&, Qt::ItemSelectionMode, Qt::SortOrder, QTransform const&) const + 315
    10. 8 QtGui 0x0000000135a709bf QGraphicsScene::items(QRectF const&, Qt::ItemSelectionMode) const + 111
    11. 9 QtGui 0x0000000135a893cf QGraphicsScene::render(QPainter*, QRectF const&, QRectF const&, Qt::AspectRatioMode) + 271
    12. 10 INScore 0x00000001315fba38 inscore::VSceneView::copy(unsigned int*, int, int, bool) + 280
    13. 11 INScore 0x000000013152e286 inscore::IGlue::getSceneView(unsigned int*, int, int, bool) + 294
    14. 12 INScore 0x0000000131608946 inscore::INScore::getScene(inscore::IGlue*, unsigned int*, int, int) + 22
    15. 13 libjniINScore.dylib 0x0000000117bfa613 Java_INScore_INScore_GetBitmap + 83
    16. 14 ??? 0x000000010301265b 0 + 4345374299
    17. ...
    18. 30 ??? 0x00000001030013eb 0 + 4345304043
    19. 31 libclient64.dylib 0x000000010109e249 JVM_Lseek + 185699
    20. 32 libclient64.dylib 0x000000010109e041 JVM_Lseek + 185179
    21. 33 libclient64.dylib 0x00000001010a8d2b JVM_StartThread + 2355
    22. 34 libclient64.dylib 0x00000001010a8c1e JVM_StartThread + 2086
    23. 35 libclient64.dylib 0x00000001010a8b89 JVM_StartThread + 1937
    24. 36 libclient64.dylib 0x00000001010a8a29 JVM_StartThread + 1585
    25. 37 libclient64.dylib 0x00000001010a88d3 JVM_StartThread + 1243
    26. 38 libclient64.dylib 0x000000010100cad2 JNI_CreateJavaVM_Impl + 46704
    27. 39 libSystem.B.dylib 0x00007fff859ed536 _pthread_start + 331
    28. 40 libSystem.B.dylib 0x00007fff859ed3e9 thread_start + 13
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: non GUI thread use

    You have to explain clearly where the threads are. They are the most probable source of your problems.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: non GUI thread use

    You're right but it's quite difficult since the threads are java VM threads and there are about thirty running.
    Anyway and thanks to your previous advice (to make a minimal compilable example), I think I'm on the way to find the reason (and the solution). I need to make some more investigations but when I'll have the solution, I'll post it to this forum. Right now, it seems that the problem comes from the java side.

Similar Threads

  1. Replies: 9
    Last Post: 28th November 2009, 20:31
  2. Replies: 16
    Last Post: 7th October 2009, 08:17
  3. Replies: 6
    Last Post: 29th April 2009, 18:17
  4. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22:09

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.