From 1adb76d5c7aa9cfff6dfe781c5faa951cc730d79 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 28 Jun 2023 13:20:33 -0700 Subject: [PATCH] exception handlers for video decoder threads --- src/Video/VideoPlayer.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Video/VideoPlayer.cs b/src/Video/VideoPlayer.cs index 0c9f3e85..016d7dfe 100644 --- a/src/Video/VideoPlayer.cs +++ b/src/Video/VideoPlayer.cs @@ -174,7 +174,7 @@ namespace MoonWorks.Video } currentFrame = thisFrame; - Task.Run(CurrentStream.ReadNextFrame); + Task.Run(CurrentStream.ReadNextFrame).ContinueWith(HandleTaskException); } if (CurrentStream.Ended) @@ -182,7 +182,7 @@ namespace MoonWorks.Video timer.Stop(); timer.Reset(); - Task.Run(CurrentStream.Reset); + Task.Run(CurrentStream.Reset).ContinueWith(HandleTaskException); if (Loop) { @@ -260,13 +260,21 @@ namespace MoonWorks.Video private void InitializeDav1dStream() { - Task.Run(Video.StreamA.Reset); - Task.Run(Video.StreamB.Reset); + Task.Run(Video.StreamA.Reset).ContinueWith(HandleTaskException); + Task.Run(Video.StreamB.Reset).ContinueWith(HandleTaskException); CurrentStream = Video.StreamA; currentFrame = -1; } + private static void HandleTaskException(Task task) + { + if (task.Exception != null) + { + Logger.LogError(task.Exception.ToString()); + } + } + protected virtual void Dispose(bool disposing) { if (!disposed)