1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:43:21 +08:00

Move SkinnableInfo error handling to lower level

Handling was recently added to handle the usage in
`Skin.GetDrawableCompoent`, but it turns out this is also required for
`DrawableExtensions.ApplySkinnableInfo` which can throw in a similar
fashion.

Found while working on sprite support for the editor, where this becomes
an actual issue (ie. switching to a branch where the new sprite support
is not present can cause unexpected crashes).
This commit is contained in:
Dean Herbert 2022-04-01 14:30:02 +09:00
parent 0a86bf6fb1
commit 01829cf2d8
2 changed files with 13 additions and 13 deletions

View File

@ -9,6 +9,7 @@ using Newtonsoft.Json;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -84,9 +85,17 @@ namespace osu.Game.Screens.Play.HUD
/// <returns>The new instance.</returns> /// <returns>The new instance.</returns>
public Drawable CreateInstance() public Drawable CreateInstance()
{ {
Drawable d = (Drawable)Activator.CreateInstance(Type); try
d.ApplySkinnableInfo(this); {
return d; Drawable d = (Drawable)Activator.CreateInstance(Type);
d.ApplySkinnableInfo(this);
return d;
}
catch (Exception e)
{
Logger.Error(e, $"Unable to create skin component {Type.Name}");
return Drawable.Empty();
}
} }
} }
} }

View File

@ -155,16 +155,7 @@ namespace osu.Game.Skinning
var components = new List<Drawable>(); var components = new List<Drawable>();
foreach (var i in skinnableInfo) foreach (var i in skinnableInfo)
{ components.Add(i.CreateInstance());
try
{
components.Add(i.CreateInstance());
}
catch (Exception e)
{
Logger.Error(e, $"Unable to create skin component {i.Type.Name}");
}
}
return new SkinnableTargetComponentsContainer return new SkinnableTargetComponentsContainer
{ {