Merge pull request #2109 from peppy/sprite-text-fallback

Avoid potential stack overflow in SpriteText fallback logic
This commit is contained in:
Dan Balasescu
2019-01-23 16:08:57 +09:00
committed by GitHub

View File

@@ -61,13 +61,13 @@ namespace osu.Framework.Graphics.Sprites
invalidate(true);
}, true);
spaceWidth = GetTextureForCharacter('.')?.DisplayWidth * 2 ?? 1;
spaceWidth = getTextureForCharacter('.')?.DisplayWidth * 2 ?? 1;
sharedData.TextureShader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE);
sharedData.RoundedTextureShader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED);
// Pre-cache the characters in the texture store
foreach (var character in displayedText)
GetTextureForCharacter(character);
getTextureForCharacter(character);
}
private LocalisedString text = string.Empty;
@@ -423,7 +423,7 @@ namespace osu.Framework.Graphics.Sprites
}
else
{
texture = GetTextureForCharacter(character);
texture = getTextureForCharacter(character);
textureSize = texture == null ? new Vector2(useFixedWidth ? constantWidth : spaceWidth) : new Vector2(texture.DisplayWidth, texture.DisplayHeight);
}
@@ -512,7 +512,7 @@ namespace osu.Framework.Graphics.Sprites
}
private Cached<float> constantWidthCache;
private float constantWidth => constantWidthCache.IsValid ? constantWidthCache.Value : constantWidthCache.Value = GetTextureForCharacter('D')?.DisplayWidth ?? 0;
private float constantWidth => constantWidthCache.IsValid ? constantWidthCache.Value : constantWidthCache.Value = getTextureForCharacter('D')?.DisplayWidth ?? 0;
private Cached<Vector2> shadowOffsetCache;
private Vector2 shadowOffset => shadowOffsetCache.IsValid ? shadowOffsetCache.Value : shadowOffsetCache.Value = ToScreenSpace(shadow_offset * TextSize) - ToScreenSpace(Vector2.Zero);
@@ -582,6 +582,8 @@ namespace osu.Framework.Graphics.Sprites
#endregion
private Texture getTextureForCharacter(char c) => GetTextureForCharacter(c) ?? GetFallbackTextureForCharacter(c);
/// <summary>
/// Gets the texture for the given character.
/// </summary>
@@ -592,7 +594,7 @@ namespace osu.Framework.Graphics.Sprites
if (store == null)
return null;
return store.GetCharacter(Font, c) ?? store.GetCharacter(null, c) ?? GetFallbackTextureForCharacter(c);
return store.GetCharacter(Font, c) ?? store.GetCharacter(null, c);
}
/// <summary>