avoid TextBatch.Draw smashing the stack with big strings

main
cosmonaut 2022-06-30 13:24:51 -07:00
parent a9b3b53ce9
commit 1aa522ffa1
1 changed files with 9 additions and 5 deletions

View File

@ -35,10 +35,16 @@ namespace MoonWorks.Graphics.Font
HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment verticalAlignment = VerticalAlignment.Baseline
) {
fixed (char* chars = text)
var byteCount = System.Text.Encoding.UTF8.GetByteCount(text);
if (StringBytes.Length < byteCount)
{
System.Array.Resize(ref StringBytes, byteCount);
}
fixed (char* chars = text)
fixed (byte* bytes = StringBytes)
{
var byteCount = System.Text.Encoding.UTF8.GetByteCount(text);
var bytes = stackalloc byte[byteCount];
System.Text.Encoding.UTF8.GetBytes(chars, text.Length, bytes, byteCount);
var result = Wellspring.Wellspring_Draw(
@ -57,8 +63,6 @@ namespace MoonWorks.Graphics.Font
{
throw new System.ArgumentException("Could not decode string!");
}
PrimitiveCount += (uint) (text.Length * 2);
}
}