Qt World Summit: Submit your Presentation

(Solved) Segmentation fault QMediaPlayer on exit

  • I have been struggling with a segmentation fault for quite a while and simply can't figure out where it comes from.
    I have a videoplayer using Qt5.1 on Ubuntu 12.04 and it works as such as expected, except when I exit my application I get a segmentation fault.
    In my main I have the following piece of code to exit my application
    // Create a window to shut down the application
    QWidget window;
    QLabel *label = new QLabel("The video player application is running");
    QPushButton *button = new QPushButton("&Stop player");
    QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit()));
    QVBoxLayout *layout = new QVBoxLayout(&window);
    And my videoplayer class looks like this:
    #include <QMediaPlayer>
    #include <QVideoWidget>
    #include <QMediaPlaylist>

    class QMediaPlaylist;
    class QVideoWidget;

    namespace VideoModule

    class VideoPlayerPlugin : public QObject, VideoPlayer

    explicit VideoPlayerPlugin(QObject *parent = 0);

    bool selfTest() override;
    bool initialize() override;
    bool postInit() override;
    QStringList diagnosticInfo() const override;
    QObject *asQObject() override {return this;}
    void startPlaying() override;
    void stopPlaying() override;
    void pausePlayback() override;

    void aboutToFinish();

    public slots:
    void setNextFile(const QString &file) override;
    void stopAndClear() override;

    private slots:
    void playerStateChanged(QMediaPlayer::State state);

    QMediaPlaylist *m_playlist;
    QMediaPlayer *m_player;
    QVideoWidget *m_video;
    bool m_canPlay;

    I have run gdb and the backtrace after getting the segmentation fault looks like this:
    Program received signal SIGSEGV, Segmentation fault.
    0xb1393bf3 in QMediaPlayer::~QMediaPlayer() () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Multimedia.so.5
    (gdb) bt
    #0 0xb1393bf3 in QMediaPlayer::~QMediaPlayer() () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Multimedia.so.5
    #1 0xb1393c42 in QMediaPlayer::~QMediaPlayer() () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Multimedia.so.5
    #2 0xb777ad8c in QObjectPrivate::deleteChildren() () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5
    #3 0xb778017b in QObject::~QObject() () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5
    #4 0xb1419890 in VideoModule::VideoPlayerPlugin::~VideoPlayerPlugin (this=0x82ddf50, __in_chrg=<optimized out>)
    at ../../../MyPlayer/src/videoplayerplugin/videoplayerplugin.h:11
    #5 0xb14198d5 in VideoModule::VideoPlayerPlugin::~VideoPlayerPlugin (this=0x82ddf50, __in_chrg=<optimized out>)
    at ../../../MyPlayer/src/videoplayerplugin/videoplayerplugin.h:11
    #6 0xb7744168 in ?? () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5
    #7 0xb77482c4 in ?? () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5
    #8 0xb72702fb in __cxa_finalize (d=0xb7972440) at cxa_finalize.c:56
    #9 0xb755aec4 in ?? () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5
    #10 0xb77f0c7d in _fini () from /xx/Qt5.1.1/5.1.1/gcc/lib/libQt5Core.so.5
    #11 0xb7ffeff4 in ?? () from /lib/ld-linux.so.2
    #12 0xb726ff51 in __run_exit_handlers (status=0, listp=0xb73e33e4, run_list_atexit=true) at exit.c:78
    #13 0xb726ffdd in __GI_exit (status=0) at exit.c:100
    #14 0xb72564db in __libc_start_main (main=0x804959c <main(int, char**)>, argc=1, ubp_av=0xbffff234,
    init=0x804a4d0 <__libc_csu_init>, fini=0x804a540 <__libc_csu_fini>, rtld_fini=0xb7fed280 <_dl_fini>,
    stack_end=0xbffff22c) at libc-start.c:258
    #15 0x080494d1 in _start ()

    Can anyone give me a hint if I might be missing something or what else I could be doing wrong?

    EDIT: Found out the destructor tried to delete the same object twice...

Log in to reply