From 36ddb03d8f60cae5c0be2b6f663e1c125ff59a07 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 29 Jun 2023 12:14:46 -0700 Subject: [PATCH] only check video exception on thread fault --- src/Video/VideoPlayer.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Video/VideoPlayer.cs b/src/Video/VideoPlayer.cs index e7c7664..f7db51a 100644 --- a/src/Video/VideoPlayer.cs +++ b/src/Video/VideoPlayer.cs @@ -174,7 +174,7 @@ namespace MoonWorks.Video } currentFrame = thisFrame; - Task.Run(CurrentStream.ReadNextFrame).ContinueWith(HandleTaskException); + Task.Run(CurrentStream.ReadNextFrame).ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); } if (CurrentStream.Ended) @@ -182,7 +182,7 @@ namespace MoonWorks.Video timer.Stop(); timer.Reset(); - Task.Run(CurrentStream.Reset).ContinueWith(HandleTaskException); + Task.Run(CurrentStream.Reset).ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); if (Loop) { @@ -260,8 +260,8 @@ namespace MoonWorks.Video private void InitializeDav1dStream() { - Task.Run(Video.StreamA.Reset).ContinueWith(HandleTaskException); - Task.Run(Video.StreamB.Reset).ContinueWith(HandleTaskException); + Task.Run(Video.StreamA.Reset).ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); + Task.Run(Video.StreamB.Reset).ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); CurrentStream = Video.StreamA; currentFrame = -1; @@ -269,10 +269,7 @@ namespace MoonWorks.Video private static void HandleTaskException(Task task) { - if (task.Exception != null) - { - throw task.Exception; - } + throw task.Exception; } protected virtual void Dispose(bool disposing)