From 5c1b15303cf3190b9c3abf8f6844c7f128833d47 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Wed, 8 Sep 2021 14:18:55 +0200 Subject: [PATCH] UI: Try to fix crashes when creating MPV Try to force the window creation before passing the WID to MPV to fix the possibility where the window is not already created and thus everything crashes. --- src/UI/DocumentViews/MpvContainer.cc | 8 ++++++++ src/UI/DocumentViews/MpvContainer.hh | 2 ++ src/UI/DocumentViews/VideoView.cc | 2 ++ 3 files changed, 12 insertions(+) diff --git a/src/UI/DocumentViews/MpvContainer.cc b/src/UI/DocumentViews/MpvContainer.cc index b689349e..864daf03 100644 --- a/src/UI/DocumentViews/MpvContainer.cc +++ b/src/UI/DocumentViews/MpvContainer.cc @@ -19,6 +19,14 @@ MpvContainer::MpvContainer(QWidget *parent) setAttribute(Qt::WA_DontCreateNativeAncestors); setAttribute(Qt::WA_NativeWindow); +} + +void +MpvContainer::intializeMpv() +{ + if (isMpvAlreadyInitialized) + throw std::logic_error("MPV is already initialized!"); + isMpvAlreadyInitialized = true; quint64 wid = winId(); mpv_set_option(mpv, "wid", MPV_FORMAT_INT64, &wid); diff --git a/src/UI/DocumentViews/MpvContainer.hh b/src/UI/DocumentViews/MpvContainer.hh index 70804554..677d945c 100644 --- a/src/UI/DocumentViews/MpvContainer.hh +++ b/src/UI/DocumentViews/MpvContainer.hh @@ -32,6 +32,7 @@ class MpvContainer final : public QWidget { private: bool isPlaybackPaused{ true }; + bool isMpvAlreadyInitialized{ false }; mpv_handle *volatile mpv{ nullptr }; qint64 sid{ -1 }; std::function<void(double)> mpvTimeCallback{ nullptr }; @@ -39,6 +40,7 @@ private: public: explicit MpvContainer(QWidget *parent); + void intializeMpv(); ~MpvContainer() noexcept override; void loadFile(const QString &) noexcept; diff --git a/src/UI/DocumentViews/VideoView.cc b/src/UI/DocumentViews/VideoView.cc index 30eee0e0..2e45fcfd 100644 --- a/src/UI/DocumentViews/VideoView.cc +++ b/src/UI/DocumentViews/VideoView.cc @@ -14,6 +14,8 @@ VideoView::VideoView(QWidget *parent) noexcept centralLayout->addWidget(new MpvControls(mpv, this)); setLayout(centralLayout); + + mpv->intializeMpv(); } void -- GitLab