From e228c7f0118f94d9edfbe6717c948dc4e38cd256 Mon Sep 17 00:00:00 2001 From: Georges Berenger Date: Mon, 3 Feb 2025 09:12:29 -0800 Subject: [PATCH] Fix memory error on quit Summary: Users have reported a memory corruption on quit when working with some files. When I finaly was able to reproduce the issue in the debugger, I was able to see the error happened when destroying menus. When quitting, we end up updating the menus during teardown, which looks like it's the cause of the issues. By preventing menu updates during teardown, I can't repro the issue again. note: this bug used to be fairly rare, but recent changes have made it much more frequent. Differential Revision: D68998315 fbshipit-source-id: 7fc54436e49fac26fd8fabea2220fea192bf2455 --- tools/vrsplayer/FileReader.cpp | 1 - tools/vrsplayer/PlayerWindow.cpp | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/vrsplayer/FileReader.cpp b/tools/vrsplayer/FileReader.cpp index 6b915997..2333459e 100644 --- a/tools/vrsplayer/FileReader.cpp +++ b/tools/vrsplayer/FileReader.cpp @@ -1303,7 +1303,6 @@ void FileReader::setState(FileReaderState newState) { time_.pause(); } } - cout << "Video state: " << FileReaderStateConverter::toString(newState) << "\n"; mediaStateChanged(state_); } diff --git a/tools/vrsplayer/PlayerWindow.cpp b/tools/vrsplayer/PlayerWindow.cpp index cafbbf95..1f5545da 100644 --- a/tools/vrsplayer/PlayerWindow.cpp +++ b/tools/vrsplayer/PlayerWindow.cpp @@ -161,6 +161,9 @@ void PlayerWindow::updateLayoutAndPresetMenu( const QVariant& currentPreset) { layoutMenu_->clear(); layoutActionsAndPreset_.clear(); + if (player_.getFileReader().getState() == FileReaderState::NoMedia) { + return; + } if (visibleCount < frameCount) { unique_ptr layoutAction = make_unique(QString("Show All Streams"), this); connect(layoutAction.get(), &QAction::triggered, [this]() { player_.showAllStreams(); }); @@ -237,6 +240,9 @@ void PlayerWindow::updateLayoutAndPresetMenu( void PlayerWindow::updateTextOverlayMenu() { textOverlayMenu_->clear(); + if (player_.getFileReader().getState() == FileReaderState::NoMedia) { + return; + } QColor color = player_.getOverlayColor(); addColorAction(color, Qt::white, "Use White"); addColorAction(color, Qt::black, "Use Black"); @@ -270,6 +276,9 @@ void PlayerWindow::updateTextOverlayMenu() { void PlayerWindow::updateAudioMenu() { audioMenu_->clear(); audioActions_.clear(); + if (player_.getFileReader().getState() == FileReaderState::NoMedia) { + return; + } if (audioChannelCount_ == 0 || playbackChannelCount_ == 0) { auto noAudioAction = make_unique( audioChannelCount_ == 0 ? "No Playable Audio" : "No Audio Playback Device", this);