From a1d3335410281491e7ad61a44e2e9b225fe3c813 Mon Sep 17 00:00:00 2001 From: David Rickard Date: Tue, 3 Sep 2024 06:17:57 -0700 Subject: [PATCH] Prevented rare crash when moving mouse over the preset tree --- .../Controls/PresetTreeViewContainer.xaml.cs | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/VidCoder/Controls/PresetTreeViewContainer.xaml.cs b/VidCoder/Controls/PresetTreeViewContainer.xaml.cs index 39c93ec3..67ec629f 100644 --- a/VidCoder/Controls/PresetTreeViewContainer.xaml.cs +++ b/VidCoder/Controls/PresetTreeViewContainer.xaml.cs @@ -186,28 +186,34 @@ private void OnPresetTreeItemMouseDown(object sender, MouseButtonEventArgs e) private void OnPresetTreeItemMouseMove(object sender, MouseEventArgs e) { - if (e.LeftButton == MouseButtonState.Pressed) - { - Point currentPosition = e.GetPosition(this.presetTreeView); - var timeSinceLastResize = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowReize; - var timeSinceLastMove = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowMove; - - // For some reason there is a hang on DoDragDrop if we are resizing or moving the encode settings window on top of another window. - // Suppress drag drop in this case. - if (timeSinceLastResize > TimeSpan.FromMilliseconds(500) - && timeSinceLastMove > TimeSpan.FromMilliseconds(500) - && DragDropUtilities.IsMovementBigEnough(this.lastPresetTreeViewMouseDown, currentPosition)) - { - this.draggedPreset = this.presetTreeView.SelectedItem as PresetViewModel; - - if (this.draggedPreset != null) - { - this.windowManager.SuspendDropOnWindows(); - DragDrop.DoDragDrop((DependencyObject)sender, this.presetTreeView.SelectedItem, DragDropEffects.Move); - this.windowManager.ResumeDropOnWindows(); - } - } - } + try + { + if (e.LeftButton == MouseButtonState.Pressed) + { + Point currentPosition = e.GetPosition(this.presetTreeView); + var timeSinceLastResize = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowReize; + var timeSinceLastMove = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowMove; + + // For some reason there is a hang on DoDragDrop if we are resizing or moving the encode settings window on top of another window. + // Suppress drag drop in this case. + if (timeSinceLastResize > TimeSpan.FromMilliseconds(500) + && timeSinceLastMove > TimeSpan.FromMilliseconds(500) + && DragDropUtilities.IsMovementBigEnough(this.lastPresetTreeViewMouseDown, currentPosition)) + { + this.draggedPreset = this.presetTreeView.SelectedItem as PresetViewModel; + + if (this.draggedPreset != null) + { + this.windowManager.SuspendDropOnWindows(); + DragDrop.DoDragDrop((DependencyObject)sender, this.presetTreeView.SelectedItem, DragDropEffects.Move); + this.windowManager.ResumeDropOnWindows(); + } + } + } + } catch (Exception exception) + { + StaticResolver.Resolve().LogError("Error processing mouse move on preset tree:" + Environment.NewLine + exception); + } } private void ShowFolderMoveAdorner(TreeViewItem item)