creating a scene crashes program when I close dialog



  • Hi All,
    I've got a test for graphics view in a dialog constructor. To load an image. It works fine. However when I click on X to close the dialog it crashes the program. What I've found if I use a q scene ( which I need to ) this causes a crash and seg fault. Scene is defined in my dialog class. My code is

        ui->setupUi(this);
    
       QPixmap pix( "/home/tjh/Desktop/test/test.png" );
    
        QGraphicsPixmapItem* pixMapItem = new QGraphicsPixmapItem();
        pixMapItem->setPixmap( pix );
        pixMapItem->setPos( 20, 20 );
    
    
    /*THIS IS CRASH CAUSER*/
       scene = new QGraphicsScene( this );
    
    
       scene->setSceneRect( ui->graphicsView->rect() );
       ui->graphicsView->setScene( scene );
    
           scene->addItem( pixMapItem );
    
    
       ui->graphicsView->show();
    

    Can anyone advise why this would happen? Thanks


  • Qt Champions 2016

    @tony67 said:
    Hi
    ui->graphicsView is also defined in same dialog?


  • Qt Champions 2016

    @tony67
    Hello,
    What's the stack trace? Do you explicitly delete the scene in the destructor of the dialog, try not doing it and see how it goes.

    Kind regards.



  • Hi ,
    I believe I'm closing in deconstructor, I've tried every combination of the following, eg with all three, with only ui and scene. So
    Should add made pixmapitem part of class in case this was issue, made no difference.

    Game_TestGame_Dialog::~Game_TestGame_Dialog()
    {
        delete pixMapItem;
        delete scene;
        delete ui;
    }
    

    my stack shows
    0 _GI_rise
    1 GI_abort
    2 _libc_message
    3 _GI__fortify_fail
    4 _stack_Chk_fail
    5 MainWindow::on_actionPlay_Game_triggered
    6 MainWindow::qt_static_metacall
    7 MainWindow::qt_metacall
    8 QMetaObject::active(QObject* int, int, void**)
    ......

    Can anyone advise on this please?


  • Qt Champions 2016

    @tony67 said:

    scene = new QGraphicsScene( this );

    Here you give "this" as parent. If that is dialog, dialog owns the scene and will delete
    when its delted itself.

    So try to
    // delete scene;
    so you dont also delete it.


  • Qt Champions 2016

    @tony67
    You had corrupted the memory somewhere (probably in the MainWindow::on_actionPlay_Game_triggered slot) judging from the stack. So focus on that, instead of thinking about the destructor. My guess it you have either overflowed a buffer, or you are modifying some foreign memory. Check the slot, and if in need of help post it's contents here.

    Kind regards.



  • Hi
    First thankyou for all the advise.
    it's a bit odd, too me at least as I'm just doing the following

    void MainWindow::on_actionPlay_Game_triggered()
    {
    bunch of warning boxes here....
    
    
        Game_TestGame_Dialog mGame_TestGame_Dialog;
        mGame_TestGame_Dialog.exec( );
    
    }
    

    when I step through it crashes on leaving the action trigger, so on entering the stack is
    0 MainWindow::on_actionPlay_Game_triggered mainwindow.cpp 701 0x41694c
    1 MainWindow::qt_static_metacall moc_mainwindow.cpp 192 0x566b41
    2 MainWindow::qt_metacall moc_mainwindow.cpp 224 0x566c38
    3 QMetaObject::activate(QObject*, int, int, void**) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6fb4ae2
    4 QAction::triggered(bool) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7883722
    5 QAction::activate(QAction::ActionEvent) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7885e28
    6 ?? /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a0918a
    7 ?? /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a0ebd4
    8 QMenu::mouseReleaseEvent(QMouseEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a1383e
    9 QWidget::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff78d11e8
    10 QMenu::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a14053
    11 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff788db2c
    12 QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff78938eb
    13 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6f83c2b
    .........

    when I exit ( step to curly brace ), it crashes with

    The inferior stopped because it received a signal from the Operating System.
    
    Signal name : 
    SIGABRT
    Signal meaning : 
    Aborted
    
    

    and the stack shows
    0 __GI_raise 55 0x7ffff5e97267
    1 __GI_abort 89 0x7ffff5e98eca
    2 __libc_message 175 0x7ffff5edac53
    3 __GI___fortify_fail 38 0x7ffff5f7ae8c
    4 __stack_chk_fail 28 0x7ffff5f7ae30
    5 MainWindow::on_actionPlay_Game_triggered mainwindow.cpp 705 0x416a54
    6 MainWindow::qt_static_metacall moc_mainwindow.cpp 192 0x566b41
    7 MainWindow::qt_metacall moc_mainwindow.cpp 224 0x566c38
    8 QMetaObject::activate(QObject*, int, int, void**) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6fb4ae2
    9 QAction::triggered(bool) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7883722
    10 QAction::activate(QAction::ActionEvent) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7885e28
    11 ?? /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a0918a
    12 ?? /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a0ebd4
    13 QMenu::mouseReleaseEvent(QMouseEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a1383e
    14 QWidget::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff78d11e8
    15 QMenu::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff7a14053
    16 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff788db2c
    17 QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff78938eb
    18 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6f83c2b
    19 QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff78923da
    20 ?? /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff78e9a43
    ... <More>



  • right this is totally nuts, it's caused by the warning message boxes , 4 of then checking for sprites , sound effects ect. What I did was comment them all out using /**/
    eg

    /*
        if( Sprites.get_size( ) == 0 )
        {
           QMessageBox::critical(this, tr("Warning"),tr(" No Sprites for game"),QMessageBox::Close );
           return;
        }
    */
    

    Then allowed one through at a time. Then the whole lot. Now it works no crashes :s. Literally all I've done is put in comments compile, uncomment and compile, so it's exactly as it was, but now it works... Out of curiosity can anyone advise how this could happen?


  • Qt Champions 2016

    @tony67
    This could happen if you had some left-over object files and your compiler didn't recreate them. So when the linker makes the executable it'd be using outdated translation units and creates an executable that crashes. Or you have an error that's intermittently causing the crash (for example buffer that may or may not overwrite memory you don't own depending on the starting/running conditions).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.