Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Error when exiting program with qDebug() output



  • Greetings:

    I have an OpenGL Qt application and when I launch it from the command line and pass it the --verbose argument to turn on output from qDebug(), I get errors when I exit the application. If that flag is not passed and, therefore, qDebug() is not called, the application exits successfully. How can I gracefully exit? Thank you for your help with this; it is much appreciated.

    Error:

    Foo(36726,0x7fffa465a380) malloc: *** error for object 0x7f876e49fad0: pointer being freed was not allocated
    *** set a breakpoint in malloc_error_break to debug
    Abort trap: 6
    

    Application Information:

    • On macOS, I launch the application on the terminal to get the output by doing the following: ./Foo.app/Contents/MacOS/Foo --verbose
    • Code and object creation is similar to "Hello GL2 Example" at Hello GL2 Example

    System Information:

    • macOS 10.13.6
    • issue occurs with Qt versions 5.11.2, 5.11.3, and 5.12.0

    Kind regards,
    Anthel


  • Qt Champions 2017

    Looks like one of the objects is getting deleted through parent and object is not dynamically created. Just check your code.



  • Greetings:

    I believe @dheerendra is correct and that I was ultimately bit by the compiler. My GLWidget::cleanup() is called twice. When I put some printf() statements throughout this function the error went away. So, when I leave one within my if (m_program == nullptr) block, I suddenly do not get the error. Is there a common pragma or something else I can do to this evaluation besides the printf() to force the compiler to not get cute in this portion of the code? Thank you for the very prompt response on this and this forum's help!

    void GLWidget::cleanup()
    {
        if (m_program == nullptr)
        {
            printf("INFO:GLWidget:cleanup: Successfully exited OpenGL Widget\n");
            return;
        }
        makeCurrent();
        m_entitySurfVbo.destroy();
        m_entityAxesVbo.destroy();
        m_entityPtsVbo.destroy();
        delete m_program;
        m_program = NULL;
        doneCurrent();
    }
    

    My compiler information is below.

    $ g++ --version
    g++ (MacPorts gcc8 8.2.0_3) 8.2.0
    Copyright (C) 2018 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    Kind regards,
    Anthel



  • Greetings:

    I ended up just putting a single ; instead of the printf() and now things work as expected. I cannot figure out a better cross-compiler way of addressing this. If someone else does, then please post. Again, thank you for your help with this.

    Kind regards,
    Anthel


Log in to reply