From 580c31cccee1646db85bbf3a033911858bf79d7a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Fri, 19 Sep 2025 13:31:03 +0200 Subject: informationpanel: prevent a crash when creating video preview panel and a media file is selected To reproduce the crash: - Open Dolphin, disable information panel and close Dolphin - Re-open Dolphin - Select a video file - Enable information panel - Crash Problem is that some elements of the MediaWidget panel are created when the widget is shown, in `showEvent` (`m_seekSlider` and `m_topLayout`), and these elements are called before being created. This MR fixes 2 different crashes: - Crash creating panel when a video file is selected (call to `m_seekSlider` before its creation) - Crash creating panel when a video file is selected and autoplay enabled (call to `m_topLayout` before its creation) --- src/panels/information/informationpanelcontent.cpp | 6 ++---- src/panels/information/mediawidget.cpp | 10 ++++++++-- src/panels/information/mediawidget.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index afca9a76c..285ce3ae9 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -501,10 +501,8 @@ void InformationPanelContent::adjustWidgetSizes(int width) // try to increase the preview as large as possible m_preview->setSizeHint(QSize(maxWidth, maxWidth)); - if (m_mediaWidget->isVisible()) { - // assure that the size of the video player is the same as the preview size - m_mediaWidget->setVideoSize(QSize(maxWidth, maxWidth)); - } + // assure that the size of the video player is the same as the preview size + m_mediaWidget->setVideoSize(QSize(maxWidth, maxWidth)); } #include "moc_informationpanelcontent.cpp" diff --git a/src/panels/information/mediawidget.cpp b/src/panels/information/mediawidget.cpp index 2ab6803e8..20366445a 100644 --- a/src/panels/information/mediawidget.cpp +++ b/src/panels/information/mediawidget.cpp @@ -151,7 +151,9 @@ void MediaWidget::setUrl(const QUrl &url, MediaKind kind) if (m_url != url) { m_url = url; m_isVideo = kind == MediaKind::Video; - m_seekSlider->setValue(0); + if (m_seekSlider) { + m_seekSlider->setValue(0); + } } if (m_autoPlay) { play(); @@ -220,7 +222,11 @@ void MediaWidget::showEvent(QShowEvent *event) QWidget::showEvent(event); return; } + initLayout(); +} +void MediaWidget::initLayout() +{ if (!m_topLayout) { m_topLayout = new QVBoxLayout(this); m_topLayout->setContentsMargins(0, 0, 0, 0); @@ -285,6 +291,7 @@ void MediaWidget::onStateChanged(QMediaPlayer::PlaybackState newState) void MediaWidget::initPlayer() { if (!m_player) { + initLayout(); m_player = new QMediaPlayer; m_player->setAudioOutput(new QAudioOutput); @@ -294,7 +301,6 @@ void MediaWidget::initPlayer() m_videoWidget->installEventFilter(this); m_player->setVideoOutput(m_videoWidget); m_topLayout->insertWidget(0, m_videoWidget); - applyVideoSize(); connect(m_player, &QMediaPlayer::playbackStateChanged, this, &MediaWidget::onStateChanged); diff --git a/src/panels/information/mediawidget.h b/src/panels/information/mediawidget.h index bd04266e6..f5b970d5e 100644 --- a/src/panels/information/mediawidget.h +++ b/src/panels/information/mediawidget.h @@ -70,6 +70,7 @@ private: void applyVideoSize(); void togglePlayback(); void initPlayer(); + void initLayout(); QUrl m_url; QSize m_videoSize; -- cgit v1.3