1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Fix UpdateableBeatmapBackgroundSprite not disposing of previously loaded sprites

This commit is contained in:
Jamie Taylor 2019-03-06 18:18:47 +09:00
parent 00cdb3a44a
commit eb80549782
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C

View File

@ -9,7 +9,7 @@ using osu.Framework.Graphics.Containers;
namespace osu.Game.Beatmaps.Drawables namespace osu.Game.Beatmaps.Drawables
{ {
/// <summary> /// <summary>
/// Display a baetmap background from a local source, but fallback to online source if not available. /// Display a beatmap background from a local source, but fallback to online source if not available.
/// </summary> /// </summary>
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo> public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo>
{ {
@ -26,37 +26,51 @@ namespace osu.Game.Beatmaps.Drawables
this.beatmapSetCoverType = beatmapSetCoverType; this.beatmapSetCoverType = beatmapSetCoverType;
} }
protected override Drawable CreateDrawable(BeatmapInfo model) private BeatmapInfo lastModel;
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Drawable content, double timeBeforeLoad)
{ {
return new DelayedLoadUnloadWrapper(() => return new DelayedLoadUnloadWrapper(() =>
{ {
Drawable drawable; // 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.
if (lastModel == Beatmap.Value)
return CreateDrawable(Beatmap.Value);
var localBeatmap = beatmaps.GetWorkingBeatmap(model); // 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;
if (model?.BeatmapSet?.OnlineInfo != null) return content;
drawable = new BeatmapSetCover(model.BeatmapSet, beatmapSetCoverType);
else if (localBeatmap.BeatmapInfo.ID != 0)
{
// Fall back to local background if one exists
drawable = new BeatmapBackgroundSprite(localBeatmap);
}
else
{
// Use the default background if somehow an online set does not exist and we don't have a local copy.
drawable = new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
}
drawable.RelativeSizeAxes = Axes.Both;
drawable.Anchor = Anchor.Centre;
drawable.Origin = Anchor.Centre;
drawable.FillMode = FillMode.Fill;
drawable.OnLoadComplete = d => d.FadeInFromZero(400);
return drawable;
}, 500, 10000); }, 500, 10000);
} }
protected override double FadeDuration => 0; protected override Drawable CreateDrawable(BeatmapInfo model)
{
Drawable drawable;
var localBeatmap = beatmaps.GetWorkingBeatmap(model);
if (model?.BeatmapSet?.OnlineInfo != null)
{
drawable = new BeatmapSetCover(model.BeatmapSet, beatmapSetCoverType);
}
else if (localBeatmap.BeatmapInfo.ID != 0)
{
// Fall back to local background if one exists
drawable = new BeatmapBackgroundSprite(localBeatmap);
}
else
{
// Use the default background if somehow an online set does not exist and we don't have a local copy.
drawable = new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
}
drawable.RelativeSizeAxes = Axes.Both;
drawable.Anchor = Anchor.Centre;
drawable.Origin = Anchor.Centre;
drawable.FillMode = FillMode.Fill;
drawable.OnLoadComplete = d => d.FadeInFromZero(400);
return drawable;
}
} }
} }