From 3c68a6684ea0bedbc5e93d9cfc9b1c3033ff58b2 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 27 Nov 2022 00:45:14 -0600 Subject: [PATCH] LibVideo: Don't crash when a decoder error is encountered while seeking When errors are encountered by PlaybackManager, it attempts to switch states to either Stopped or Corrupted. However, that causes it to set the last presentation media time to the current playback time while the last presentation time is unexpectedly negative because the seek never ended. Ending the seek before the state changes to Stopped or Corrupted prevents this situation from happening. --- Userland/Libraries/LibVideo/PlaybackManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index 17d2c52f33..2332f69494 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -106,6 +106,11 @@ Time PlaybackManager::duration() void PlaybackManager::on_decoder_error(DecoderError error) { + // If we don't switch to playing/paused before stopping/becoming corrupted, the player will crash + // due to the invalid playback time. + if (is_seeking()) + end_seek(); + switch (error.category()) { case DecoderErrorCategory::EndOfStream: dbgln_if(PLAYBACK_MANAGER_DEBUG, "{}", error.string_literal());