fadden / CiderPress2

Tool for working with Apple II and vintage Mac disk images and file archives.
https://ciderpress2.com/
Apache License 2.0
50 stars 7 forks source link

WPF control crash while using "Find" feature #22

Open fadden opened 5 months ago

fadden commented 5 months ago

When finding files in the GUI, the application tries to scroll the window contents so that the found item is selected. It needs to do this in the file list and, for hierarchical filesystems, in the directory tree.

The application has a DirectoryTreeItem method called BringItemIntoView that took several hours and a couple of stackoverflow posts to figure out. It calls an internal VirtualizingPanel method called BringIndexIntoView. Most of the time this works, but sometimes it crashes like this:

 ---> System.InvalidOperationException: Cannot call StartAt when content generation is in progress.
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Nullable`1& lastPagePixelSize, Boolean remeasure)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
[...]
   at System.Windows.Controls.VirtualizingStackPanel.BringIndexIntoView(Int32 index)

The next Find operation blows up while trying to traverse the TreeView.

These failures can be ignored, since ultimately it just means that the directory tree isn't getting scrolled, but it's not ideal.

Reproduction steps:

Unrelated but interesting: if you select an item in the file list in the middle of a large archive, and move the scrollbar elsewhere, sometimes the file view jumps back to the item if you move the directory tree scrollbar around. More weird interactions with virtualization?

fadden commented 4 months ago

Patched in v1.0.3-dev1: https://github.com/fadden/CiderPress2/releases/tag/v1.0.3-dev1