Results 1 to 2 of 2

Thread: Application crashes when associating one object with two others

  1. #1
    Join Date
    Sep 2015
    Posts
    50
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Application crashes when associating one object with two others

    Hello all,

    I have been modifying the sample application located here: http://doc.qt.io/qt-5/qtwidgets-grap...e-example.html and converted it from a Scene to a View based app. I have added my own QGraphicsPolygonItem called PhysParticle.

    The goal of the application is to create particles and apply vectors to them. They should move around the screen and drag the vectors with them.

    The following cases work:
    Arrow-end of vector connects to a particle
    start of vector connects to particle
    vector by itself (no particles attached to start or end)

    Crashes the application: Both the start and end of vector connects to two separate particles.

    I have narrowed it down to a single line of code but it makes absolutely no sense. All it is doing is a member variable assignment. if I take that one item out of the code, everything runs but of course the two particles are not connected.

    Qt Code:
    1. Arrow *PhysGraphicsView::createVector(QPointF StartPt, QPointF EndPt, PhysParticle *pStartItem, PhysParticle *pEndItem) {
    2. Arrow *pArrow = new Arrow(StartPt, EndPt);
    3. pArrow ->startItem(pStartItem);
    4. if (pStartItem) {
    5. pStartItem ->addArrow(pArrow);
    6. pArrow ->startItem(pStartItem);
    7. }
    8. if (pStartItem != pEndItem && pEndItem) {
    9. pEndItem ->addArrow(pArrow);
    10. pArrow ->endItem(pEndItem); // <---- this causes it to crash
    11. }
    12. pArrow ->setColor(m_LineColor);
    13. pArrow ->setZValue(-1000.0);
    14. m_pScene ->addItem(pArrow);
    15. pArrow ->updatePosition();
    16. return pArrow;
    17. }
    18.  
    19. // partial class definition for Arrow:
    20. class Arrow : public QGraphicsLineItem, PhysBaseItem {
    21. public:
    22. enum { Type = PhysBaseItem::VectorType };
    23.  
    24. Arrow(PhysParticle *, PhysParticle *, QGraphicsItem * = NULL);
    25. Arrow(QPointF, QPointF, QGraphicsItem * = NULL);
    26. Arrow(QPointF, QPointF, PhysParticle *, PhysParticle *, QGraphicsItem * = NULL);
    27. int type() const { return Type; }
    28. QRectF boundingRect() const;
    29. void setColor(const QColor &color) { m_Color = color; }
    30. PhysParticle *startItem() const { return m_pStartItem; }
    31. PhysParticle *endItem() const { return m_pEndItem; }
    32. void startItem(PhysParticle *pStartItem) { m_pStartItem = pStartItem; }
    33. void endItem(PhysParticle *pEndItem) { m_pEndItem = pEndItem; }
    34. private:
    35. PhysParticle *m_pStartItem, *m_pEndItem;
    To copy to clipboard, switch view to plain text mode 

    The errors I get in QTCreator in the Application output is:
    Starting .\QTGraphicsSceneExample\debug\QTGraphicsSceneExam ple.exe...
    ASSERT: "!isEmpty()" in file ../../../../Qt/5.5/mingw492_32/include/QtCore/qvector.h, line 204
    Invalid parameter passed to C runtime function.
    Invalid parameter passed to C runtime function.
    .\QTGraphicsSceneExample\debug\QTGraphicsSceneExam ple.exe exited with code 3

    And the dialog box I get is:
    crash.png

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Application crashes when associating one object with two others

    The output indicates that you are hitting an assert in QVector, i.e. trying to access and element in an empty vector.

    The assert's fatal log should be where the backtrace ends.
    What does the backtrace look like?

    Cheers,
    _

Similar Threads

  1. QT application crashes.
    By coding_neo in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2011, 13:30
  2. Qt Creat or crashes when QPrinter object is declared
    By fredykhan in forum Qt Programming
    Replies: 13
    Last Post: 18th February 2011, 18:44
  3. Application crashes when it has a particular name
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 20:50
  4. Application crashes
    By waynew in forum Newbie
    Replies: 1
    Last Post: 2nd November 2009, 10:31
  5. My application crashes
    By sophister in forum Qt Programming
    Replies: 13
    Last Post: 27th April 2009, 07:39

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.