1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 10:47:28 +08:00

Merge pull request #1581 from peppy/fix-sprite-icon

Fix SpriteIcon potentially not updating texture during a load race condition
This commit is contained in:
Dan Balasescu 2017-11-27 09:39:43 +09:00 committed by GitHub
commit d6ba5685cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,19 +57,31 @@ namespace osu.Game.Graphics
private void load(FontStore store) private void load(FontStore store)
{ {
this.store = store; this.store = store;
updateTexture(); updateTexture();
} }
protected override void LoadComplete()
{
base.LoadComplete();
updateTexture();
}
private FontAwesome loadedIcon;
private void updateTexture() private void updateTexture()
{ {
var texture = store?.Get(((char)icon).ToString()); var loadableIcon = icon;
if (loadableIcon == loadedIcon) return;
var texture = store?.Get(((char)loadableIcon).ToString());
spriteMain.Texture = texture; spriteMain.Texture = texture;
spriteShadow.Texture = texture; spriteShadow.Texture = texture;
if (Size == Vector2.Zero) if (Size == Vector2.Zero)
Size = new Vector2(texture?.DisplayWidth ?? 0, texture?.DisplayHeight ?? 0); Size = new Vector2(texture?.DisplayWidth ?? 0, texture?.DisplayHeight ?? 0);
loadedIcon = loadableIcon;
} }
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)