Results 1 to 9 of 9

Thread: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

  1. #1
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    Hello,

    while developing in qt i came across following problem (Several hours of googling gave me no answer or hint of cause):

    During shutdown of the application, it crashes while deleting instance of QGraphicsLinearLayout (A sample application which can reproduce the issue is in attachment).

    Valgrind output launching the binary and then attempting to close the window:
    Qt Code:
    1. ==13872== Memcheck, a memory error detector
    2. ==13872== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
    3. ==13872== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
    4. ==13872== Command: ./graphicstest
    5. ==13872==
    6. ==13872== Invalid read of size 4
    7. ==13872== at 0x482F852: QGraphicsWidget::~QGraphicsWidget() (in /usr/lib/libQtGui.so.4.7.3)
    8. ==13872== by 0x560B0C7: ???
    9. ==13872== Address 0x560b590 is 0 bytes inside a block of size 8 free'd
    10. ==13872== at 0x4026B2C: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    11. ==13872== by 0x47E94B9: QGraphicsLinearLayout::~QGraphicsLinearLayout() (in /usr/lib/libQtGui.so.4.7.3)
    12. ==13872== by 0x4E86232: (below main) (in /lib/libc-2.14.so)
    13. ==13872==
    14. ==13872== Invalid write of size 4
    15. ==13872== at 0x47E8EEF: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    16. ==13872== by 0x47E8FB1: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    17. ==13872== by 0x560B0C7: ???
    18. ==13872== Address 0x560b590 is 0 bytes inside a block of size 8 free'd
    19. ==13872== at 0x4026B2C: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    20. ==13872== by 0x47E94B9: QGraphicsLinearLayout::~QGraphicsLinearLayout() (in /usr/lib/libQtGui.so.4.7.3)
    21. ==13872== by 0x4E86232: (below main) (in /lib/libc-2.14.so)
    22. ==13872==
    23. ==13872== Invalid read of size 4
    24. ==13872== at 0x47E8E94: QGraphicsLayoutItem::parentLayoutItem() const (in /usr/lib/libQtGui.so.4.7.3)
    25. ==13872== by 0x47E8EF9: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    26. ==13872== by 0x47E8FB1: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    27. ==13872== by 0x560B0C7: ???
    28. ==13872== Address 0x560b594 is 4 bytes inside a block of size 8 free'd
    29. ==13872== at 0x4026B2C: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    30. ==13872== by 0x47E94B9: QGraphicsLinearLayout::~QGraphicsLinearLayout() (in /usr/lib/libQtGui.so.4.7.3)
    31. ==13872== by 0x4E86232: (below main) (in /lib/libc-2.14.so)
    32. ==13872==
    33. ==13872== Invalid read of size 4
    34. ==13872== at 0x47E8E97: QGraphicsLayoutItem::parentLayoutItem() const (in /usr/lib/libQtGui.so.4.7.3)
    35. ==13872== by 0x47E8EF9: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    36. ==13872== by 0x47E8FB1: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    37. ==13872== by 0x560B0C7: ???
    38. ==13872== Address 0x8 is not stack'd, malloc'd or (recently) free'd
    39. ==13872==
    40. ==13872==
    41. ==13872== Process terminating with default action of signal 11 (SIGSEGV)
    42. ==13872== Access not within mapped region at address 0x8
    43. ==13872== at 0x47E8E97: QGraphicsLayoutItem::parentLayoutItem() const (in /usr/lib/libQtGui.so.4.7.3)
    44. ==13872== by 0x47E8EF9: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    45. ==13872== by 0x47E8FB1: QGraphicsLayoutItem::~QGraphicsLayoutItem() (in /usr/lib/libQtGui.so.4.7.3)
    46. ==13872== by 0x560B0C7: ???
    47. ==13872== If you believe this happened as a result of a stack
    48. ==13872== overflow in your program's main thread (unlikely but
    49. ==13872== possible), you can try to increase the size of the
    50. ==13872== main thread stack using the --main-stacksize= flag.
    51. ==13872== The main thread stack size used in this run was 8388608.
    52. ==13872==
    53. ==13872== HEAP SUMMARY:
    54. ==13872== in use at exit: 659,939 bytes in 3,442 blocks
    55. ==13872== total heap usage: 31,396 allocs, 27,954 frees, 4,724,184 bytes allocated
    56. ==13872==
    57. ==13872== LEAK SUMMARY:
    58. ==13872== definitely lost: 216 bytes in 1 blocks
    59. ==13872== indirectly lost: 0 bytes in 0 blocks
    60. ==13872== possibly lost: 98,000 bytes in 1,058 blocks
    61. ==13872== still reachable: 561,723 bytes in 2,383 blocks
    62. ==13872== suppressed: 0 bytes in 0 blocks
    63. ==13872== Rerun with --leak-check=full to see details of leaked memory
    64. ==13872==
    65. ==13872== For counts of detected and suppressed errors, rerun with: -v
    66. ==13872== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 77 from 12)
    67. Segmentation fault
    To copy to clipboard, switch view to plain text mode 

    Any suggestions? I don't presume it's qt bug, perhaps i'm doing some mistake i am unaware of.

    Library and application versions:
    qt: 4.7.3-3
    qtcreator: 2.2.1-3
    valgrind: 3.6.1-2

    Thanks in advance for any reply.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    can you post the code?
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    it is in attachment as a qtcreator project, but i certainly can:

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QGraphicsScene>
    3. #include <QGraphicsView>
    4.  
    5. #include "widget.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication app(argc, argv);
    10.  
    11. widget w;
    12. scene.addItem(&w);
    13.  
    14. view.setScene(&scene);
    15. view.show();
    16.  
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    widget.h
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QGraphicsWidget>
    5. #include <QGraphicsLinearLayout>
    6.  
    7. class widget : public QGraphicsWidget {
    8. Q_OBJECT
    9. public:
    10. explicit widget(QGraphicsWidget *parent = 0) : QGraphicsWidget(parent) {
    11. w = new QGraphicsWidget();
    12. l = new QGraphicsLinearLayout();
    13. l->addItem(w);
    14. this->setLayout(l);
    15. }
    16. ~widget() {
    17. if (w != NULL) {
    18. delete w;
    19. w = NULL;
    20. }
    21. if (l != NULL) {
    22. delete l;
    23. l = NULL;
    24. }
    25. }
    26. protected:
    27. QGraphicsWidget* w;
    28. QGraphicsLinearLayout* l;
    29. };
    30. #endif
    To copy to clipboard, switch view to plain text mode 

    Thank you for a reply.

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    I think the problem is the "widget" destructor

    You have not delete widget children, Qt delete them when necessary
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    24
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    I tried to just comment the line
    Qt Code:
    1. this->setLayout(l);
    To copy to clipboard, switch view to plain text mode 
    and the crash is gone. Maybe the layout is deleted before the destructor?

  6. #6
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    that's what i always assumed as standart procedure - destructors are called implicitly when the application exits, thus the children get deleted there, however i applied following modification to demonstrate there is clearly no difference:


    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsScene>
    3. #include <QGraphicsView>
    4.  
    5. #include "widget.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication app(argc, argv);
    10.  
    11. widget w;
    12. scene.addItem(&w);
    13.  
    14. view.setScene(&scene);
    15. view.show();
    16.  
    17. QObject::connect(&app, SIGNAL(aboutToQuit()), &w,
    18. SLOT(deleteChildren()));
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    widget.h
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QGraphicsWidget>
    5. #include <QGraphicsLinearLayout>
    6.  
    7. class widget : public QGraphicsWidget {
    8. Q_OBJECT
    9. public:
    10. explicit widget(QGraphicsWidget *parent = 0) : QGraphicsWidget(parent) {
    11. w = new QGraphicsWidget();
    12. l = new QGraphicsLinearLayout();
    13. l->addItem(w);
    14. this->setLayout(l);
    15. }
    16.  
    17. ~widget() {
    18. QObject::disconnect(this, SLOT(deleteChildren()));
    19. if (w != NULL) {
    20. delete w;
    21. w = NULL;
    22. }
    23. if (l != NULL) {
    24. delete l;
    25. l = NULL;
    26. }
    27. }
    28.  
    29. public slots:
    30. void deleteChildren() {
    31. if (w != NULL) {
    32. delete w;
    33. w = NULL;
    34. }
    35. if (l != NULL) {
    36. delete l;
    37. l = NULL;
    38. }
    39. }
    40. protected:
    41. QGraphicsWidget* w;
    42. QGraphicsLinearLayout* l;
    43. };
    44. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 

    now the children get deleted when application emits signal. The result is however same - deletion of the QGraphicsLinearLayout produces crash with same valgrind output.

    Thanks for suggestion though.

    sakya: but uhm... then the widget doesn't have it's inner layout applied... you might be right however... by setting the layout, QGraphicsWidget manages it itself. So fix might be either setting layout to none before exit, or not deleting it explicitly myself.

    Going to try it, thanks.

  7. #7
    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: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    READ DOCUMENTATION:
    http://doc.qt.nokia.com/latest/qgrap...ml#layout-prop :
    QGraphicsWidget takes ownership of layout.
    http://doc.qt.nokia.com/latest/qgrap...t.html#details :
    the layout takes ownership of the items.
    So you don't have to delete anything!

  8. The following user says thank you to MarekR22 for this useful post:

    mrcz (19th July 2011)

  9. #8
    Join Date
    Jul 2011
    Location
    Italy
    Posts
    24
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    Quote Originally Posted by MarekR22 View Post
    So you don't have to delete anything!
    I knew that, but isn't strange that the program doesn't crash when deleting w (child of l)?
    W should have been deleted as a child of the layout, no?

  10. #9
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsLinearLayout::~QGraphicsLinearLayout() - crash on clean up

    perhaps there is another check performed while in case of layout isn't?

    thanks for pointing out the documentation ... seems i missed that fact.

Similar Threads

  1. Replies: 1
    Last Post: 11th March 2011, 15:56
  2. Calculate scene coordinates from QGraphicsLinearLayout
    By onurozcelik in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2011, 09:38
  3. QGraphicsLinearLayout does not behave like QVBoxLayout
    By jobrandt in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2009, 10:59
  4. QGraphicsLinearLayout
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 8th February 2009, 15:31
  5. Issue with QGraphicsLinearLayout (Qt-4.4 snapshot)
    By momesana in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2008, 03:05

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.