Fix ArgumentOutOfRangeException crash in Problems list - #355
Open
hendrikmennen wants to merge 1 commit into
Open
Fix ArgumentOutOfRangeException crash in Problems list#355hendrikmennen wants to merge 1 commit into
hendrikmennen wants to merge 1 commit into
Conversation
Avalonia's DataGridCollectionView.ProcessRemoveEvent does not check PassesFilter (unlike ProcessAddEvent). When an item that is filtered out of the view is removed from the source collection, removeIndex is -1, so AdjustCurrencyForRemove(-1) takes the `index < CurrentPosition` branch and sets CurrentPosition to -1 while CurrentItem is still in view. The following IsCurrentInSync check then calls GetItemAt(-1) and throws. In practice this crashed the app whenever a problem row at position 0 was current and a filtered-out error was removed, e.g. from IErrorService.RefreshErrors during AI project diagnostics refresh. Route all removal paths of the error list through a new BatchObservableCollection that suppresses notifications and raises a single Reset, which DataGridCollectionView handles via a safe full refresh that restores currency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The app crashes with:
Root cause
Upstream bug in Avalonia's
DataGridCollectionView:ProcessRemoveEventdoes not checkPassesFilter(unlikeProcessAddEvent).When an item that is filtered out of the view is removed from the source collection:
removeIndex = IndexOf(removedItem)is-1needToRemoveis stilltrue(internalRemoveIndex < (PageIndex + 1) * PageSize→-1 < 0)AdjustCurrencyForRemove(-1)takes theindex < CurrentPositionbranch and doesSetCurrent(CurrentItem, CurrentPosition - 1)→CurrentPosition == -1whileCurrentItemis still in the viewCurrentPosition >= Countguard doesn't catch a negative positionIsCurrentInSync→IsCurrentInViewistrue→GetItemAt(-1)throwsSo it reproduces whenever a problem row at position 0 is current and a filtered-out error is removed — exactly what
IErrorService.RefreshErrorsdoes during an AI project diagnostics refresh.Fix
Added
BatchObservableCollection<T>, which suppresses change notifications while a batch of mutations is applied and raises a singleResetafterwards.DataGridCollectionViewhandlesResetviaRefreshOrDefer()→RefreshOverride(), which rebuilds the view and restores currency throughResetCurrencyValues, bypassing the broken incremental-remove path entirely.All removal paths in
ErrorListViewModelare now batched:RefreshErrors,ClearFile,Clear(source),Clear(project)andClear(project, source). NoResetis raised if the batch didn't actually change anything, so unchanged diagnostics refreshes stay free.Verification
Standalone repro against
Avalonia.Controls.DataGrid:The batched collection completes cleanly and preserves the current item/position.
dotnet build src/OneWare.ErrorList/OneWare.ErrorList.csprojsucceeds with 0 errors.