mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 22:22:55 +08:00
Merge pull request #334 from peppy/memory-fixes
Fix major memory leak when MusicController is hidden
This commit is contained in:
commit
6f45217b02
@ -23,6 +23,7 @@ using osu.Game.Configuration;
|
|||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
@ -229,6 +230,12 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
|
if (pendingBeatmapSwitch != null)
|
||||||
|
{
|
||||||
|
pendingBeatmapSwitch();
|
||||||
|
pendingBeatmapSwitch = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (current?.TrackLoaded ?? false)
|
if (current?.TrackLoaded ?? false)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -320,43 +327,50 @@ namespace osu.Game.Overlays
|
|||||||
base.PerformLoad(game);
|
base.PerformLoad(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Action pendingBeatmapSwitch;
|
||||||
|
|
||||||
private void updateDisplay(WorkingBeatmap beatmap, TransformDirection direction)
|
private void updateDisplay(WorkingBeatmap beatmap, TransformDirection direction)
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
//we might be off-screen when this update comes in.
|
||||||
|
//rather than Scheduling, manually handle this to avoid possible memory contention.
|
||||||
|
pendingBeatmapSwitch = () =>
|
||||||
{
|
{
|
||||||
if (beatmap?.Beatmap == null)
|
Task.Run(() =>
|
||||||
//todo: we may need to display some default text here (currently in the constructor).
|
|
||||||
return;
|
|
||||||
|
|
||||||
BeatmapMetadata metadata = beatmap.Beatmap.BeatmapInfo.Metadata;
|
|
||||||
title.Text = unicodeString(metadata.Title, metadata.TitleUnicode);
|
|
||||||
artist.Text = unicodeString(metadata.Artist, metadata.ArtistUnicode);
|
|
||||||
});
|
|
||||||
|
|
||||||
MusicControllerBackground newBackground;
|
|
||||||
|
|
||||||
(newBackground = new MusicControllerBackground(beatmap)).Preload(game, delegate
|
|
||||||
{
|
|
||||||
|
|
||||||
dragContainer.Add(newBackground);
|
|
||||||
|
|
||||||
switch (direction)
|
|
||||||
{
|
{
|
||||||
case TransformDirection.Next:
|
if (beatmap?.Beatmap == null)
|
||||||
newBackground.Position = new Vector2(400, 0);
|
//todo: we may need to display some default text here (currently in the constructor).
|
||||||
newBackground.MoveToX(0, 500, EasingTypes.OutCubic);
|
return;
|
||||||
backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic);
|
|
||||||
break;
|
|
||||||
case TransformDirection.Prev:
|
|
||||||
newBackground.Position = new Vector2(-400, 0);
|
|
||||||
newBackground.MoveToX(0, 500, EasingTypes.OutCubic);
|
|
||||||
backgroundSprite.MoveToX(400, 500, EasingTypes.OutCubic);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
backgroundSprite.Expire();
|
BeatmapMetadata metadata = beatmap.Beatmap.BeatmapInfo.Metadata;
|
||||||
backgroundSprite = newBackground;
|
title.Text = unicodeString(metadata.Title, metadata.TitleUnicode);
|
||||||
});
|
artist.Text = unicodeString(metadata.Artist, metadata.ArtistUnicode);
|
||||||
|
});
|
||||||
|
|
||||||
|
MusicControllerBackground newBackground;
|
||||||
|
|
||||||
|
(newBackground = new MusicControllerBackground(beatmap)).Preload(game, delegate
|
||||||
|
{
|
||||||
|
|
||||||
|
dragContainer.Add(newBackground);
|
||||||
|
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case TransformDirection.Next:
|
||||||
|
newBackground.Position = new Vector2(400, 0);
|
||||||
|
newBackground.MoveToX(0, 500, EasingTypes.OutCubic);
|
||||||
|
backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic);
|
||||||
|
break;
|
||||||
|
case TransformDirection.Prev:
|
||||||
|
newBackground.Position = new Vector2(-400, 0);
|
||||||
|
newBackground.MoveToX(0, 500, EasingTypes.OutCubic);
|
||||||
|
backgroundSprite.MoveToX(400, 500, EasingTypes.OutCubic);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
backgroundSprite.Expire();
|
||||||
|
backgroundSprite = newBackground;
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Func<string, string, string> unicodeString;
|
private Func<string, string, string> unicodeString;
|
||||||
|
Loading…
Reference in New Issue
Block a user