Skip to content

Commit

Permalink
Fix RearrangeableListContainer<> crashing on replacement operations
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Nov 14, 2024
1 parent 9e38585 commit 23443bf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions osu.Framework/Graphics/Containers/RearrangeableListContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ private void sortItems()
{
for (int i = 0; i < Items.Count; i++)
{
var drawable = itemMap[Items[i]];
// A drawable for the item may not exist yet, for example in a replace-range operation where the removal happens first.
if (!itemMap.TryGetValue(Items[i], out var drawable))
continue;

// The item may not be loaded yet, because add operations are asynchronous.
if (drawable.Parent != ListContainer)
continue;

// If the async load didn't complete, the item wouldn't exist in the container and an exception would be thrown
if (drawable.Parent == ListContainer)
ListContainer!.SetLayoutPosition(drawable, i);
ListContainer!.SetLayoutPosition(drawable, i);
}
}

Expand Down

0 comments on commit 23443bf

Please sign in to comment.