sbaeumlisberger / VirtualizingWrapPanel

Implementation of a comprehensive VirtualisingWrapPanel for WPF
MIT License
254 stars 35 forks source link

[NOMERGE] Items Taller Than View Cause Infinite Loop #34

Closed nietras closed 2 years ago

nietras commented 2 years ago

@sbaeumlisberger there appears to be a bug related to navigating items when items are larger than view i.e. with this change height=1000 causes infinite loop or a very long loop when pressing arrow key down to navigate to items one row down.

image

Call stack when in infinite loop looks something like:

>   System.Private.CoreLib.dll!System.Threading.Monitor.Enter(object obj, ref bool lockTaken) Line 54   C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.FromThread(System.Threading.Thread thread) Line 88  C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.CurrentDispatcher.get() Line 67 C#
    WindowsBase.dll!System.Windows.Freezable.Freezable() Line 53    C#
    PresentationCore.dll!System.Windows.Media.RenderDataDrawingContext.PushGuidelineY1(double coordinate) Line 1184 C#
    PresentationCore.dll!MS.Internal.TextFormatting.DrawingState.DrawingState(System.Windows.Media.DrawingContext drawingContext, System.Windows.Point lineOrigin, System.Windows.Media.MatrixTransform antiInversion, MS.Internal.TextFormatting.TextMetrics.FullTextLine currentLine) Line 67 C#
    PresentationCore.dll!MS.Internal.TextFormatting.TextMetrics.FullTextLine.DrawTextLine(System.Windows.Media.DrawingContext drawingContext, System.Windows.Point origin, System.Windows.Media.MatrixTransform antiInversion) Line 606 C#
    PresentationCore.dll!MS.Internal.TextFormatting.TextMetrics.FullTextLine.Draw(System.Windows.Media.DrawingContext drawingContext, System.Windows.Point origin, System.Windows.Media.TextFormatting.InvertAxes inversion) Line 583   C#
    PresentationFramework.dll!MS.Internal.Text.Line.Render(System.Windows.Media.DrawingContext ctx, System.Windows.Point lineOffset) Line 128   C#
    PresentationFramework.dll!System.Windows.Controls.TextBlock.OnRender(System.Windows.Media.DrawingContext ctx) Line 1665 C#
    PresentationCore.dll!System.Windows.UIElement.Arrange(System.Windows.Rect finalRect) Line 938   C#
    PresentationFramework.dll!System.Windows.Controls.StackPanel.StackArrangeHelper(System.Windows.Controls.IStackMeasure arrangeElement, System.Windows.Controls.IStackMeasureScrollData scrollData, System.Windows.Size arrangeSize) Line 750 C#
    PresentationFramework.dll!System.Windows.Controls.StackPanel.ArrangeOverride(System.Windows.Size arrangeSize) Line 706  C#
    PresentationFramework.dll!System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect finalRect) Line 4726  C#
    PresentationCore.dll!System.Windows.UIElement.Arrange(System.Windows.Rect finalRect) Line 894   C#
    PresentationFramework.dll!MS.Internal.Helper.ArrangeElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size arrangeSize) Line 551  C#
    PresentationFramework.dll!System.Windows.Controls.ContentPresenter.ArrangeOverride(System.Windows.Size arrangeSize) Line 504    C#
    PresentationFramework.dll!System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect finalRect) Line 4726  C#
    PresentationCore.dll!System.Windows.UIElement.Arrange(System.Windows.Rect finalRect) Line 894   C#
    PresentationFramework.dll!System.Windows.Controls.Border.ArrangeOverride(System.Windows.Size finalSize) Line 281    C#
    PresentationFramework.dll!System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect finalRect) Line 4726  C#
    PresentationCore.dll!System.Windows.UIElement.Arrange(System.Windows.Rect finalRect) Line 894   C#
    PresentationFramework.dll!System.Windows.Controls.Control.ArrangeOverride(System.Windows.Size arrangeBounds) Line 735   C#
    PresentationFramework.dll!System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect finalRect) Line 4726  C#
    PresentationCore.dll!System.Windows.UIElement.Arrange(System.Windows.Rect finalRect) Line 894   C#
    VirtualizingWrapPanel.dll!WpfToolkit.Controls.VirtualizingWrapPanel.ArrangeOverride(System.Windows.Size finalSize) Line 238 C#
    PresentationFramework.dll!System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect finalRect) Line 4726  C#
    PresentationCore.dll!System.Windows.UIElement.Arrange(System.Windows.Rect finalRect) Line 894   C#
    PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() Line 351    C#
    PresentationCore.dll!System.Windows.UIElement.UpdateLayout() Line 1648  C#
    PresentationFramework.dll!System.Windows.Controls.ItemsControl.MakeVisible(System.Windows.FrameworkElement container, System.Windows.Input.FocusNavigationDirection direction, bool alwaysAtTopOfViewport) Line 2716    C#
    PresentationFramework.dll!System.Windows.Controls.ItemsControl.NavigateByLine(System.Windows.Controls.ItemsControl.ItemInfo startingInfo, System.Windows.FrameworkElement startingElement, System.Windows.Input.FocusNavigationDirection direction, System.Windows.Controls.ItemsControl.ItemNavigateArgs itemNavigateArgs) Line 1941   C#
    PresentationFramework.dll!System.Windows.Controls.ItemsControl.NavigateByLine(System.Windows.Input.FocusNavigationDirection direction, System.Windows.Controls.ItemsControl.ItemNavigateArgs itemNavigateArgs) Line 1876    C#
    PresentationFramework.dll!System.Windows.Controls.ListBox.OnKeyDown(System.Windows.Input.KeyEventArgs e) Line 375   C#
    PresentationCore.dll!System.Windows.UIElement.OnKeyDownThunk(object sender, System.Windows.Input.KeyEventArgs e) Line 2016  C#
    PresentationCore.dll!System.Windows.Input.KeyEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget) Line 173    C#
    PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target) Line 336  C#
    PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Line 84 C#
    PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Line 207   C#
    PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Line 2340 C#
    PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args) Line 457   C#
    PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea() Line 829    C#
    PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input) Line 575 C#
    PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport) Line 104  C#
    PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawKeyboardActions actions, int scanCode, bool isExtendedKey, bool isSystemKey, int virtualKey) Line 870 C#
    PresentationCore.dll!System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(ref System.Windows.Interop.MSG msg, ref bool handled) Line 540   C#
    PresentationCore.dll!System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(ref System.Windows.Interop.MSG msg, System.Windows.Input.ModifierKeys modifiers) Line 2338  C#
    PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessage(object param) Line 1830  C#
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 103 C#
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 36 C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Line 1331 C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) Line 1052  C#
    PresentationCore.dll!System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(ref System.Windows.Interop.MSG msg, ref bool handled) Line 1775 C#
    PresentationCore.dll!System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(ref System.Windows.Interop.MSG msg, ref bool handled) Line 2793   C#
    WindowsBase.dll!System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(ref System.Windows.Interop.MSG msg) Line 100    C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Line 2137 C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Line 331  C#
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() Line 299  C#
    PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Line 2405 C#
    PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Line 1695    C#
    PresentationFramework.dll!System.Windows.Application.Run() Line 198 C#
    VirtualizingWrapPanelSamples.dll!VirtualizingWrapPanelSamples.App.Main()    Unknown

Doing the same with normal WrapPanel does not result in an infinite loop.

We would very much appreciate if there is a fix for this.

sbaeumlisberger commented 2 years ago

Hi, your problem does not seem to occur with the current version. Your branch is 18 commits behind the master.

Let me know if you still have problems with the current version.

nietras commented 2 years ago

@sbaeumlisberger sorry, yes it appears to have been fixed! Wonderful 👍