{"action":"created","issue":{"url":"https://api.github.com/repos/wang-bin/QtAV/issues/518","labels_url":"https://api.github.com/repos/wang-bin/QtAV/issues/518/labels{/name}","comments_url":"https://api.github.com/repos/wang-bin/QtAV/issues/518/comments","events_url":"https://api.github.com/repos/wang-bin/QtAV/issues/518/events","html_url":"https://github.com/wang-bin/QtAV/issues/518","id":108282608,"number":518,"title":"Strange behavior (and crashes) when deleting AVPlayer (also affecting QFileDialog)","user":{"login":"agudpp","id":1697015,"avatar_url":"https://avatars.githubusercontent.com/u/1697015?v=3","gravatar_id":"","url":"https://api.github.com/users/agudpp","html_url":"https://github.com/agudpp","followers_url":"https://api.github.com/users/agudpp/followers","following_url":"https://api.github.com/users/agudpp/following{/other_user}","gists_url":"https://api.github.com/users/agudpp/gists{/gist_id}","starred_url":"https://api.github.com/users/agudpp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agudpp/subscriptions","organizations_url":"https://api.github.com/users/agudpp/orgs","repos_url":"https://api.github.com/users/agudpp/repos","events_url":"https://api.github.com/users/agudpp/events{/privacy}","received_events_url":"https://api.github.com/users/agudpp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-25T08:17:14Z","updated_at":"2015-09-30T08:45:01Z","closed_at":null,"body":"Hi WangBin, first of all congrats for the awesome lib :), really nice!.\r\nI'm reporting an issue since I already spend some time on this and maybe you know what can be happening.\r\nI'm using the lib in one project and I started having a strange issue with the QFileDialog, after I delete the first QtAV::AVPlayer and then try to open a QFileDialog Qt freezes, I tried to debug but couldn't find the cause of it.\r\nLater I decided to create a small sample and project using your sample code \r\n\r\n```\r\nQHBoxLayout* mainLayout = new QHBoxLayout(this);\r\nQtAV::WidgetRenderer* renderer = new QtAV::WidgetRenderer(this);\r\nrenderer->show();\r\navplayer = new QtAV::AVPlayer;\r\navplayer->setRenderer(renderer);\r\navplayer->play(\"tmp_video.mp4\");\r\nmainLayout->addWidget(renderer);\r\n```\r\n\r\nthis code is inside of a Wrapper that creates the video player and shows the video playing correctly.\r\nLater in the destructor I just delete the avplayer \r\n```\r\ndelete avplayer;\r\n```\r\n\r\nI had 3 buttons in the main window, one that creates a new wrapper and put it into a vector. Another button that removes all the instances created. And the third one that opens a file dialog. If I open the file dialog N times works perfectly as it should. If I create M VideoWrappers all of them are created properly and play the video properly as well. If I delete all of them also, and then I can recreate as many video players as I want and works perfectly. The strange thing is after I destroy the first (or second) AVPlayer and try to open the file dialog. If I'm executing normally (debug / release but without gdb) it is crashing the second time I do this: (create video player, delete video player, open file dialog, create video player, delete video player, open file dialog -> crash).\r\nIf I execute the same code with gdb, then it is not crashing but where is happening the crash the QFileDialog is changing the style (the first time shows normally, the second times is completely different). I guess is a threading problem since the timing (gdb is slower).\r\nI tried to not destroy the AVPlayer (only), so leaving a leak, and the behavior is perfectly normal. I can create as many video players and the QFileDialog still works properly.\r\n\r\nI tried with other Dialogs and is not happening (normal QDialog) when I execute them, so I'm not really sure why is affecting the QFileDialog.\r\n\r\nSome of the errors I got (when opening the file dialog) are:\r\n```\r\n....\r\nCoCreateInstance failed ()\r\n```\r\nBut I'm not completely sure if this is related or not (sometimes when it not crash also appears).\r\n\r\n\r\nThe file dialog code is trivial:\r\n```\r\nQFileDialog fileDialog(0,\r\n                       \"file\",\r\n                       \"\",\r\n                       \"Any (*.*)\");\r\n\r\nif (!fileDialog.exec()) {\r\n    return;\r\n}\r\n```\r\n\r\nI hope you have any idea why this could be happening :).\r\n\r\nI'm using Windows 8.1, MinGW4.8.2_32 , Qt5.3, QtAv 1.8.0 (2015-09-01), ffmpeg one version but not the standard (anyway is not a ffmpeg problem I guess because the videos are working perfectly).\r\n\r\nThanks a lot in advance,\r\n \r\n"},"comment":{"url":"https://api.github.com/repos/wang-bin/QtAV/issues/comments/144329469","html_url":"https://github.com/wang-bin/QtAV/issues/518#issuecomment-144329469","issue_url":"https://api.github.com/repos/wang-bin/QtAV/issues/518","id":144329469,"user":{"login":"agudpp","id":1697015,"avatar_url":"https://avatars.githubusercontent.com/u/1697015?v=3","gravatar_id":"","url":"https://api.github.com/users/agudpp","html_url":"https://github.com/agudpp","followers_url":"https://api.github.com/users/agudpp/followers","following_url":"https://api.github.com/users/agudpp/following{/other_user}","gists_url":"https://api.github.com/users/agudpp/gists{/gist_id}","starred_url":"https://api.github.com/users/agudpp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agudpp/subscriptions","organizations_url":"https://api.github.com/users/agudpp/orgs","repos_url":"https://api.github.com/users/agudpp/repos","events_url":"https://api.github.com/users/agudpp/events{/privacy}","received_events_url":"https://api.github.com/users/agudpp/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T08:45:01Z","updated_at":"2015-09-30T08:45:01Z","body":"Hi there, sorry, here it is\r\n**main.cpp**\r\n\r\n```\r\n\r\n#include <QLayout>\r\n#include <QHBoxLayout>\r\n#include <QPushButton>\r\n#include <QStatusBar>\r\n#include <QApplication>\r\n\r\n#include <QtAV/QtAV>\r\n#include <QtAVWidgets/QtAVWidgets>\r\n\r\n#include \"TestClasses.h\"\r\n\r\nint\r\nmain(int argc, char *argv[])\r\n{\r\n    QtAV::Widgets::registerRenderers();\r\n\r\n    QApplication a(argc, argv);\r\n\r\n    QMainWindow mainWin;\r\n    mainWin.show();\r\n\r\n    QWidget widget;\r\n    HandlerHelper handlerHelper;\r\n    QHBoxLayout* m_mainLayout = new QHBoxLayout(&widget);\r\n\r\n    // create buttons\r\n    QPushButton* btnCreate = new QPushButton;\r\n    QPushButton* btnClear = new QPushButton;\r\n    QPushButton* btnDialog = new QPushButton;\r\n    btnCreate->setText(\"CreateVideoPlayers\");\r\n    btnClear->setText(\"DestroyVideoPlayers\");\r\n    btnDialog->setText(\"FileDialog\");\r\n    m_mainLayout->addWidget(btnCreate);\r\n    m_mainLayout->addWidget(btnClear);\r\n    m_mainLayout->addWidget(btnDialog);\r\n\r\n    // connect the buttons\r\n    QObject::connect(btnCreate, SIGNAL(clicked()), &handlerHelper, SLOT(onCreateInstancePressed()));\r\n    QObject::connect(btnClear, SIGNAL(clicked()), &handlerHelper, SLOT(onDeleteInstancesPressed()));\r\n    QObject::connect(btnDialog, SIGNAL(clicked()), &handlerHelper, SLOT(onOpenFileDialogPressed()));\r\n\r\n    // set the main layout and widget\r\n    widget.setLayout(m_mainLayout);\r\n    mainWin.layout()->addWidget(&widget);\r\n\r\n    mainWin.show();\r\n\r\n\r\n    return a.exec();\r\n}\r\n```\r\n\r\n**TestClasses.h**\r\n```\r\n\r\n#ifndef TESTCLASSES_H\r\n#define TESTCLASSES_H\r\n\r\n#include <QMainWindow>\r\n#include <QThread>\r\n#include <QFileDialog>\r\n#include <QHBoxLayout>\r\n\r\n#include <QtAV/QtAV>\r\n#include <QtAVWidgets/QtAVWidgets>\r\n\r\n\r\nclass WidgetWrapper : public QWidget {\r\npublic:\r\n    WidgetWrapper(QWidget* p = 0) : QWidget(p), avplayer(0)\r\n    {\r\n        QHBoxLayout* mainLayout = new QHBoxLayout(this);\r\n\r\n\r\n        QtAV::WidgetRenderer* renderer = new QtAV::WidgetRenderer(this);\r\n        renderer->show();\r\n        avplayer = new QtAV::AVPlayer;\r\n        avplayer->setRenderer(renderer);\r\n        avplayer->play(\"C:\\\\tmp_video.mp4\");\r\n        mainLayout->addWidget(renderer);\r\n    }\r\n\r\n    virtual ~WidgetWrapper()\r\n    {\r\n        if (avplayer) {\r\n            delete avplayer;\r\n            //avplayer->deleteLater();\r\n        }\r\n    }\r\n\r\nprivate:\r\n    QtAV::AVPlayer* avplayer;\r\n\r\n};\r\n\r\nclass HandlerHelper : public QObject {\r\n\r\n    Q_OBJECT\r\n\r\npublic:\r\n    HandlerHelper(){};\r\n    virtual ~HandlerHelper(){}\r\n\r\npublic slots:\r\n\r\n    void\r\n    onDeleteInstancesPressed(void)\r\n    {\r\n        for (WidgetWrapper* vp : videoPlayers) {\r\n            delete vp;\r\n            //vp->deleteLater();\r\n        }\r\n        videoPlayers.clear();\r\n    }\r\n\r\n    void\r\n    onCreateInstancePressed(void)\r\n    {\r\n        // create a video player here\r\n        for (int i = 0 ; i < 1; ++i) {\r\n            WidgetWrapper* wwrapper = new WidgetWrapper;\r\n            wwrapper->show();\r\n            videoPlayers.push_back(wwrapper);\r\n        }\r\n    }\r\n\r\n    void\r\n    onOpenFileDialogPressed(void)\r\n    {\r\n        QFileDialog fileDialog(0,\r\n                               \"Package File\",\r\n                               \"\",\r\n                               \"Any (*.*)\");\r\n\r\n        if (!fileDialog.exec()) {\r\n            // nothing to do\r\n            return;\r\n        }\r\n    }\r\n\r\nprivate:\r\n    std::vector<WidgetWrapper*> videoPlayers;\r\n};\r\n\r\n\r\n#endif // TESTCLASSES_H\r\n```\r\n\r\n**project.pro** this is a simplified version of it but should work, note there are paths to where the QtAV libs are, so you should configure this by yourself.\r\n```\r\nQT       += core gui\r\n\r\ngreaterThan(QT_MAJOR_VERSION, 4): QT += widgets\r\n\r\nDEFINES -= UNICODE\r\n\r\nTARGET = VideoPlayerTest\r\nTEMPLATE = app\r\n\r\n# DEPENDENCIES_PATH is where the \"lib/\" \"include\" folders are for the QtAVWidgets\r\nQMAKE_CXXFLAGS += -isystem $$DEPENDENCIES_PATH/include\r\n\r\nCONFIG(debug, debug|release) {\r\n    # debug mode\r\n    LIBS += -lQtAVWidgetsd1 -lQtAVd1\r\n} else {\r\n    # release / deploy\r\n    LIBS += -lQtAVWidgets1 -lQtAV1\r\n}\r\n\r\nQMAKE_CXXFLAGS += -std=c++11 -Wno-trigraphs -fwrapv -DDEBUG\r\n\r\nSOURCES += main.cpp\r\n\r\nHEADERS  += ../VideoPlayer.h \\\r\n    TestClasses.h\r\n```\r\n\r\n\r\nTo reproduce:\r\n- press create button.\r\n- press destroy button\r\n- press file dialog and close it\r\n- press create button\r\n- press destroy button\r\n- press file dialog (and it crashes).\r\n\r\nif you do the same a little bit slower then it should change the \"style\" of the QFileDialog.\r\n\r\nthanks in advance\r\n"}}