Results 1 to 6 of 6

Thread: Does qgraphicsscene schedule updates in a separate thread?

  1. #1
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Does qgraphicsscene schedule updates in a separate thread?

    Hi,

    I've noticed that if I add a large number of objects to a scene and then start deleting them very quickly (commanded by a keystroke from my parent widget) I can actually crash qgraphicsscene. I'm not sure what's happening, but I get the impression that while I am deleting the objects qgraphicsscene starts a redraw/update and while it's updating I delete more objects and a pointer probably goes null and it crashes.

    When I debug my app during the crash I see the second to last function call is:

    Qt Code:
    1. class QGraphicsSceneFindItemBspTreeVisitor : public QGraphicsSceneBspTreeVisitor
    2. {
    3. public:
    4. QList<QGraphicsItem *> *foundItems;
    5.  
    6. void visit(QList<QGraphicsItem *> *items)
    7. {
    8. for (int i = 0; i < items->size(); ++i) {
    9. QGraphicsItem *item = items->at(i);
    10. if (!item->d_func()->itemDiscovered && item->isVisible()) {
    11. item->d_func()->itemDiscovered = 1;
    12. foundItems->prepend(item);
    13. }
    14. }
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 

    The crash is on the d_func() call.

    I've added print statements to make sure I am not leaking objects from the scene and everything looks accounted for. In fact, it appears my delete runs and then a fraction of a second later I get the crash while the scene tries to render.

    My code is always calling removeItem() first, then delete;

    So is it possible that my delete code is running in one thread while the update runs in another and my delete is running "ahead" of the render which causes a problem?

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

    Default Re: Does qgraphicsscene schedule updates in a separate thread?

    Quote Originally Posted by xenome View Post
    So is it possible that my delete code is running in one thread while the update runs in another and my delete is running "ahead" of the render which causes a problem?
    No, graphics view doesn't use external threads. Your code for deleting items is simply invalid. You can't delete items which are subject to signals or events which is probably what you are doing.
    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.


  3. #3
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Does qgraphicsscene schedule updates in a separate thread?

    Thanks for the response.

    After talking to some people in the #qt IRC channel they think this might actually be a bug with QGraphicsScene in the above mentioned routine. Someone suggested I turn off BSP indexing (which I did), and the problem went away.

    Thanks

  4. The following user says thank you to xenome for this useful post:

    medved6 (3rd March 2011)

  5. #4
    Join Date
    Dec 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Does qgraphicsscene schedule updates in a separate thread?

    I've got exactly same issue!
    Thanks!

  6. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Does qgraphicsscene schedule updates in a separate thread?

    It looks like a bug.
    IMHO when you are want to delete QGraphicsItem you don't have to call anything before! So try omit call of QGraphicsScene::removeItem() when you are planning to delete object it may fix the problem.

  7. #6
    Join Date
    Jul 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Does qgraphicsscene schedule updates in a separate thread?

    Hi,

    I am able to repeat this bug 100% reliably in the current build of Fritzing (unfortunately). It takes quite a few steps to set it up, so making a simple case out of it will be very difficult. The bug occurs under Windows 4.7.0 (with a compiled Qt) and also under Mac 4.7.3 with the standard carbon Qt download.

    As with the case in this thread, it has to do with using a custom boundingRect() function for a QGraphicsItem subclass. My suspicion at the moment, though I have no proof and may be completely wrong, is that it is arising because the boundingRect in this case is highly dynamic.

Similar Threads

  1. Thread updates progress bar
    By GianMarco in forum Qt Programming
    Replies: 7
    Last Post: 12th October 2009, 13:29
  2. QGraphicsScene render thread
    By nicolas1 in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2008, 12:57
  3. handling paintGL in a separate thread
    By al101 in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2007, 17:04
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. Replies: 10
    Last Post: 20th March 2007, 22:19

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.