Results 1 to 5 of 5

Thread: Crash in q_atomic_increment

  1. #1
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Crash in q_atomic_increment

    I have a backend thread that parses the Apache configuration files and builds a tree (ConfigTree is the base class). Now I'm writing a dialog with a model and a view to let the user view the tree. It may be opened through the menu in the main window but the application crashes just on opening it. This is the backtrace:
    Qt Code:
    1. #0 0x0805a644 in q_atomic_increment (ptr=0x20) at /usr/lib/qt4/include/QtCore/qatomic_i386.h:70
    2. #1 0x0805a6ab in QBasicAtomic::ref (this=0x20) at /usr/lib/qt4/include/QtCore/qatomic.h:71
    3. #2 0x080653e5 in QList (this=0xbfc12a60, l=@0x8287098) at /usr/lib/qt4/include/QtCore/qlist.h:90
    4. #3 0x08066b88 in ConfigTree::children (this=0x8287080) at configtree.cpp:66
    5. #4 0x081010a5 in ParsedTreeModel::rowCount (this=0x83bdee8, parent=@0x84853f8) at parsedtreemodel.cpp:183
    6. #5 0xb7453bc5 in QAbstractItemModel::hasChildren (this=0x83bdee8, parent=@0x84853f8) at kernel/qabstractitemmodel.cpp:1286
    7. #6 0xb7cb3b2b in QTreeViewPrivate::hasVisibleChildren (this=0x8473660, parent=@0x84853f8) at itemviews/qtreeview.cpp:2830
    8. #7 0xb7cb3f35 in QTreeView::drawBranches (this=0x83ed4c0, painter=0xbfc12f90, rect=@0xbfc12cf8, index=@0x84853f8)
    9. at itemviews/qtreeview.cpp:1270
    10. #8 0xb7cb121c in QTreeView::drawRow (this=0x83ed4c0, painter=0xbfc12f90, option=@0xbfc12e7c, index=@0x84853f8)
    11. at itemviews/qtreeview.cpp:1207
    12. #9 0xb7cb1955 in QTreeView::drawTree (this=0x83ed4c0, painter=0xbfc12f90, region=@0xbfc13730) at itemviews/qtreeview.cpp:1046
    13. #10 0xb7cb29f3 in QTreeView::paintEvent (this=0x83ed4c0, event=0xbfc13714) at itemviews/qtreeview.cpp:988
    14. #11 0xb78830cd in QWidget::event (this=0x83ed4c0, event=0xbfc13714) at kernel/qwidget.cpp:5707
    15. #12 0xb7b8e54c in QFrame::event (this=0x83ed4c0, e=0xbfc13714) at widgets/qframe.cpp:633
    16. #13 0xb7c0abe5 in QAbstractScrollArea::viewportEvent (this=0x83ed4c0, e=0xbfc13714) at widgets/qabstractscrollarea.cpp:841
    17. #14 0xb7c7a81b in QAbstractItemView::viewportEvent (this=0x83ed4c0, event=0xbfc13714) at itemviews/qabstractitemview.cpp:1273
    18. #15 0xb7c0daa6 in QAbstractScrollAreaPrivate::viewportEvent (this=0x8473660, event=0xbfc13714) at widgets/qabstractscrollarea_p.h:78
    19. #16 0xb7c0dad8 in QAbstractScrollAreaFilter::eventFilter (this=0x83bde20, o=0x83dc048, e=0xbfc13714) at widgets/qabstractscrollarea_p.h:89
    20. #17 0xb783058e in QApplicationPrivate::notify_helper (this=0x818d208, receiver=0x83dc048, e=0xbfc13714) at kernel/qapplication.cpp:3427
    21. #18 0xb783232a in QApplication::notify (this=0xbfc14954, receiver=0x83dc048, e=0xbfc13714) at kernel/qapplication.cpp:3376
    22. #19 0xb783acb5 in QCoreApplication::sendSpontaneousEvent (receiver=0x83dc048, event=0xbfc13714)
    23. at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:186
    To copy to clipboard, switch view to plain text mode 

    It's crashing in ConfigTree::children() which simply returns the children of a given node:

    Qt Code:
    1. QList<ConfigNode*> ConfigTree::children()
    2. {
    3. return m_children;
    4. }
    To copy to clipboard, switch view to plain text mode 

    It's called by the model in rowCount(). The line 183 is the return.

    Qt Code:
    1. int ParsedTreeModel::rowCount(const QModelIndex &parent) const
    2. {
    3. if(!m_parser)
    4. return 0;
    5.  
    6. ConfigTree *parentTree;
    7. QMutexLocker locker(m_parser->parsedTreeMutex());
    8.  
    9. if (!parent.isValid())
    10. parentTree = m_parser->parsedTree();
    11. else {
    12. parentTree = static_cast<ConfigTree*>(parent.internalPointer());
    13. if(!parentTree)
    14. return 0;
    15. }
    16.  
    17. return parentTree->children().size();
    18. }
    To copy to clipboard, switch view to plain text mode 

    The parent ConfigTree belongs to the Parser, which runs in the backend thread. So the source of the problem may come that way but I've no idea why it crashes. Any idea?

  2. #2
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Crash in q_atomic_increment

    BTW, I'm using Qt 4.2.0.

    It might also be interesting for you to know ConfigTree is not a QObject.
    Last edited by vfernandez; 30th December 2006 at 17:09.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Crash in q_atomic_increment

    Quote Originally Posted by vfernandez View Post
    I have a backend thread that parses the Apache configuration files and builds a tree (ConfigTree is the base class).
    What data do you pass between that thread and the GUI?

    Quote Originally Posted by vfernandez View Post
    #0 0x0805a644 in q_atomic_increment (ptr=0x20) at /usr/lib/qt4/include/QtCore/qatomic_i386.h:70
    #1 0x0805a6ab in QBasicAtomic::ref (this=0x20)
    It seems that you have a null pointer somewhere.

  4. #4
    Join Date
    Jan 2006
    Location
    Innsbruck, Austria
    Posts
    62
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Crash in q_atomic_increment

    I think I've found the problem. The static_cast doesn't return a NULL pointer as qobject_cash does when the object can't be casted because it's not a subclass/parent class. I didn't know this behavior. The tree may contain other objects that are not subclasses of ConfigTree (the real base subclass is ConfigNode and ConfigTree is a direct subclass of ConfigNode). So as soon as an object that was not a subclass of ConfigTree appeared, the cast worked while it shouldn't have worked. That made the mess.

  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: Crash in q_atomic_increment

    I think you wanted to use dynamic_cast static_cast is equivalent to plain C cast
    Qt Code:
    1. Type *obj =(Type*)xyz;
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to wysota for this useful post:

    vfernandez (30th December 2006)

Similar Threads

  1. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27
  2. Crash caused by QVariant (mis)use
    By mclark in forum Newbie
    Replies: 2
    Last Post: 31st October 2006, 15:05
  3. sendPostedEvents crash
    By stinos in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2006, 09:43
  4. Crash: using a dialog in a model
    By Brandybuck in forum Qt Programming
    Replies: 3
    Last Post: 11th April 2006, 01:39
  5. QDockWidget: Debugging crash
    By carsten in forum Qt Programming
    Replies: 10
    Last Post: 7th January 2006, 10:50

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.