From eba72fa3a7e5d6f94b57ee8b03bf5b4c6b433772 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Mon, 24 Apr 2023 21:13:40 -0500 Subject: [PATCH] LibVideo/VP9: Wait for workers to finish when there are decoding errors Previously, the `Parser::decode_tiles()` function wouldn't wait for the tile-decoding workers to finish before exiting the function, which could mean that the data the threads are working with could become invalid if the decoder is deleted after an error is encountered. --- Userland/Libraries/LibVideo/VP9/Parser.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibVideo/VP9/Parser.cpp b/Userland/Libraries/LibVideo/VP9/Parser.cpp index 4e660564ff..f7fca00ad5 100644 --- a/Userland/Libraries/LibVideo/VP9/Parser.cpp +++ b/Userland/Libraries/LibVideo/VP9/Parser.cpp @@ -930,10 +930,16 @@ DecoderErrorOr Parser::decode_tiles(FrameContext& frame_context) } // Decode the first column in this thread. - TRY(decode_tile_column(tile_workloads[0])); + auto result = decode_tile_column(tile_workloads[0]); - for (auto& worker_thread : m_worker_threads) - TRY(worker_thread->wait_until_task_is_finished()); + for (auto& worker_thread : m_worker_threads) { + auto task_result = worker_thread->wait_until_task_is_finished(); + if (!result.is_error() && task_result.is_error()) + result = move(task_result); + } + + if (result.is_error()) + return result; #else for (auto& column_workloads : tile_workloads) TRY(decode_tile_column(column_workloads));