Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VirtualisedListContainer rows not returning pooled content in a different way #6318

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ public void TestVirtualisedList()
});
}

[Test]
public void TestVirtualisedListDisposal()
{
ExampleVirtualisedList list = null!;
AddStep("create list nested in container", () =>
{
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Child = list = new ExampleVirtualisedList
{
RelativeSizeAxes = Axes.Both,
}
}
};
list.RowData.AddRange(Enumerable.Range(1, 10000).Select(i => $"Item #{i}"));
});
AddStep("clear", Clear);
AddUntilStep("wait for async disposal", () => list.IsDisposed);
}

[Test]
public void TestCollectionChangeHandling()
{
Expand Down
19 changes: 5 additions & 14 deletions osu.Framework/Graphics/Containers/VirtualisedListContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ private void itemsChanged(object? sender, NotifyCollectionChangedEventArgs e)
Debug.Assert(e.OldItems != null);

for (int i = 0; i < e.OldItems.Count; ++i)
Items.Remove(items[e.OldStartingIndex + i], true);
{
var item = items[e.OldStartingIndex + i];
item.Unload();
Items.Remove(item, true);
}

for (int i = e.OldStartingIndex + e.OldItems.Count; i < items.Length; ++i)
Items.SetLayoutPosition(items[i], i - e.OldItems.Count);
Expand Down Expand Up @@ -250,19 +254,6 @@ public void Unload()
Visible = false;
LifetimeEnd = double.NegativeInfinity;
}

protected override void Dispose(bool isDisposing)
{
// CompositeDrawable only disposes the child pooled drawable (if any).
// This is generally not what we want for two reasons:
// - We want to try to return the pooled drawable to the pool so that it can be reused.
// Disposing it obviously makes reuse impossible.
// - Secondly, pooled drawables return to pool when they lose their parent.
// Thus, we proactively clear the pool drawable from ourselves here.
Unload();

base.Dispose(isDisposing);
}
}

protected abstract ScrollContainer<Drawable> CreateScrollContainer();
Expand Down
Loading