mirror of
https://github.com/osukey/osukey.git
synced 2025-05-05 05:37:18 +09:00
Fix background unloading/reloading sometimes crashing
This commit is contained in:
parent
1d2db85866
commit
a00e2b18a9
@ -1,10 +1,12 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -86,8 +88,61 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddStep("online (login first)", () => { });
|
AddStep("online (login first)", () => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestUnloadAndReload()
|
||||||
|
{
|
||||||
|
var backgrounds = new List<TestUpdateableBeatmapBackgroundSprite>();
|
||||||
|
ScrollContainer scrollContainer = null;
|
||||||
|
|
||||||
|
AddStep("create backgrounds hierarchy", () =>
|
||||||
|
{
|
||||||
|
FillFlowContainer backgroundFlow;
|
||||||
|
|
||||||
|
Child = scrollContainer = new ScrollContainer
|
||||||
|
{
|
||||||
|
Size = new Vector2(500),
|
||||||
|
Child = backgroundFlow = new FillFlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Spacing = new Vector2(10),
|
||||||
|
Padding = new MarginPadding { Bottom = 250 }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 25; i++)
|
||||||
|
{
|
||||||
|
var background = new TestUpdateableBeatmapBackgroundSprite { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
|
if (i % 2 == 0)
|
||||||
|
background.Beatmap.Value = testBeatmap.Beatmaps.First();
|
||||||
|
|
||||||
|
backgroundFlow.Add(new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Height = 100,
|
||||||
|
Masking = true,
|
||||||
|
Child = background
|
||||||
|
});
|
||||||
|
|
||||||
|
backgrounds.Add(background);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var loadedBackgrounds = backgrounds.Where(b => b.ContentLoaded);
|
||||||
|
|
||||||
|
int initialLoadCount = 0;
|
||||||
|
|
||||||
|
AddUntilStep("some loaded", () => (initialLoadCount = loadedBackgrounds.Count()) > 0);
|
||||||
|
AddStep("scroll to bottom", () => scrollContainer.ScrollToEnd());
|
||||||
|
AddUntilStep("some unloaded", () => loadedBackgrounds.Count() < initialLoadCount);
|
||||||
|
}
|
||||||
|
|
||||||
private class TestUpdateableBeatmapBackgroundSprite : UpdateableBeatmapBackgroundSprite
|
private class TestUpdateableBeatmapBackgroundSprite : UpdateableBeatmapBackgroundSprite
|
||||||
{
|
{
|
||||||
|
protected override double UnloadDelay => 2000;
|
||||||
|
|
||||||
public bool ContentLoaded => ((DelayedLoadUnloadWrapper)InternalChildren.LastOrDefault())?.Content?.IsLoaded ?? false;
|
public bool ContentLoaded => ((DelayedLoadUnloadWrapper)InternalChildren.LastOrDefault())?.Content?.IsLoaded ?? false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,11 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
this.beatmapSetCoverType = beatmapSetCoverType;
|
this.beatmapSetCoverType = beatmapSetCoverType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delay before the background is unloaded while off-screen.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual double UnloadDelay => 10000;
|
||||||
|
|
||||||
private BeatmapInfo lastModel;
|
private BeatmapInfo lastModel;
|
||||||
|
|
||||||
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Drawable content, double timeBeforeLoad)
|
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Drawable content, double timeBeforeLoad)
|
||||||
@ -34,13 +39,13 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
{
|
{
|
||||||
// If DelayedLoadUnloadWrapper is attempting to RELOAD the same content (Beatmap), that means that it was
|
// If DelayedLoadUnloadWrapper is attempting to RELOAD the same content (Beatmap), that means that it was
|
||||||
// previously UNLOADED and thus its children have been disposed of, so we need to recreate them here.
|
// previously UNLOADED and thus its children have been disposed of, so we need to recreate them here.
|
||||||
if (lastModel == Beatmap.Value && Beatmap.Value != null)
|
if (lastModel == Beatmap.Value)
|
||||||
return CreateDrawable(Beatmap.Value);
|
return CreateDrawable(Beatmap.Value);
|
||||||
|
|
||||||
// If the model has changed since the previous unload (or if there was no load), then we can safely use the given content
|
// If the model has changed since the previous unload (or if there was no load), then we can safely use the given content
|
||||||
lastModel = Beatmap.Value;
|
lastModel = Beatmap.Value;
|
||||||
return content;
|
return content;
|
||||||
}, timeBeforeLoad, 10000);
|
}, timeBeforeLoad, UnloadDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateDrawable(BeatmapInfo model)
|
protected override Drawable CreateDrawable(BeatmapInfo model)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user