SuRGeoNix / Flyleaf

Media Player .NET Library for WinUI 3/ WPF/WinForms (based on FFmpeg/DirectX)
GNU Lesser General Public License v3.0
687 stars 92 forks source link

crash by set curtime #457

Closed Lizhengbo0304 closed 2 months ago

Lizhengbo0304 commented 2 months ago

I have a ShuttlePRO V2 peripheral that controls the player to jump forward or backward for a certain time by rotating the button, such as: 500ms, 1s, 2s, 5s, 100s, 15s, 20s, etc. When I rotate the button quickly and frequently , will cause the program to crash.

  private void AdjustPosition(TimeSpan interval, bool isForward)
    {
        try
        {
            CurrentPlayer.Pause();

            var limit = isForward ? IsMain ? (MainPlayerOutpoint + MainPlayerInpointOffset) : (VicePlayerOutpoint + VicePlayerInpointOffset) : IsMain ? MainPlayerInpointOffset : VicePlayerInpointOffset;

            if (isForward)
            {
                // 向前调整位置。
                if ((CurrentPlayer.CurTime + interval.Ticks) <= limit)
                {
                    CurrentPlayer.CurTime += interval.Ticks;
                }
                else
                {
                    // 如果超过了限制点,则将位置设置为限制点。
                    CurrentPlayer.CurTime = limit;
                }
            }
            else
            {
                // 向后调整位置。
                if ((CurrentPlayer.CurTime - interval.Ticks) >= limit)
                {
                    CurrentPlayer.CurTime -= interval.Ticks;
                }
                else
                {
                    // 如果超过了限制点,则将位置设置为限制点。
                    CurrentPlayer.CurTime = limit;
                }
            }
        }
        catch (Exception e)
        {
            e.LogError("调整位置异常");
            Console.WriteLine(e.Message);
        }
    }

PS: In most cases, no exception will occur and the program will crash directly.But one time I received the following exception EXCEPTION_1: Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at FlyleafLib.MediaFramework.MediaDecoder.VideoDecoder.DecodeFrameNext() at FlyleafLib.MediaFramework.MediaDecoder.VideoDecoder.GetFrame(Int32) at FlyleafLib.MediaPlayer.Player.ShowFramePrev() at LiveBoost.ViewModels.CombinationMainWndVm.RecordPlaybackFfPlayerShowFramePrevExecute() at Prism.Commands.DelegateCommand.Execute() at Prism.Commands.DelegateCommand.Execute(System.Object) at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute(System.Object) at System.Windows.Input.CommandManager.TranslateInput(System.Windows.IInputElement, System.Windows.Input.InputEventArgs) at System.Windows.UIElement.OnKeyDownThunk(System.Object, System.Windows.Input.KeyEventArgs) at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object) at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean) at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs) at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport) at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(System.Windows.Interop.MSG ByRef, Boolean ByRef) at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(System.Windows.Interop.MSG ByRef, System.Windows.Input.ModifierKeys) at System.Windows.Interop.HwndSource.OnPreprocessMessage(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(System.Windows.Interop.MSG ByRef, Boolean ByRef) at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(System.Object) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run()

进程已结束,退出代码为 -1,073,741,819。 EXCEPTION_2: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

SuRGeoNix commented 2 months ago

1) No need to Pause 2) If you use CurTime without Config.Player.SeekAccurate you can't really seek forward/backward. In that case just use Seek and then specify the direction. 3) Seek will not use ShowFramePrev that I can see in the exception. Probably you use stepping ShouFrame / ShowFramePrev / ShowFrameNext from another part of your code at the same time you change the CurTime and that could possible cause the crash (RecordPlaybackFfPlayerShowFramePrevExecute?)

Lizhengbo0304 commented 2 months ago

I think I know what's wrong. The outer dial is used to adjust the seconds, and the inner dial is used to adjust the frames. When turning the outer dial, I sometimes accidentally touch the inner dial at the same time, causing the time and frames to be adjusted at the same time. Thank you so much, I have solved this problem, it no longer responds to internal turntable events before stopping turning the external turntable