Use EnumerateInvocationList instead of GetInvocationList (#2303)

This commit is contained in:
srkizer 2025-06-24 05:09:48 +09:00 committed by GitHub
parent 13306e24ba
commit 03e728e129
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 402 additions and 294 deletions

View file

@ -66,7 +66,7 @@ internal sealed class DelegateFontHandle : FontHandle
var key = new DelegateFontHandle(this, buildStepDelegate);
lock (this.syncRoot)
this.handles.Add(key);
this.RebuildRecommend?.Invoke();
this.RebuildRecommend.InvokeSafely();
return key;
}
@ -259,7 +259,7 @@ internal sealed class DelegateFontHandle : FontHandle
}
}
/// <inheritdoc/>
/// <inheritdoc/>
public void OnPreBuildCleanup(IFontAtlasBuildToolkitPreBuild toolkitPreBuild)
{
// irrelevant

View file

@ -386,7 +386,7 @@ internal sealed partial class FontAtlasFactory
if (this.disposed)
return;
this.BeforeDispose?.InvokeSafely(this);
this.BeforeDispose.InvokeSafely(this);
try
{
@ -400,25 +400,11 @@ internal sealed partial class FontAtlasFactory
this.disposables.Dispose();
}
try
{
this.AfterDispose?.Invoke(this, null);
}
catch
{
// ignore
}
this.AfterDispose.InvokeSafely(this, null);
}
catch (Exception e)
{
try
{
this.AfterDispose?.Invoke(this, e);
}
catch
{
// ignore
}
this.AfterDispose.InvokeSafely(this, e);
}
GC.SuppressFinalize(this);
@ -664,7 +650,7 @@ internal sealed partial class FontAtlasFactory
{
res = new(this, scale);
foreach (var fhm in this.fontHandleManagers)
res.InitialAddSubstance(fhm.NewSubstance(res));
res.InitialAddSubstance(fhm.NewSubstance(res));
unsafe
{
atlasPtr = (nint)res.Atlas.NativePtr;
@ -699,7 +685,7 @@ internal sealed partial class FontAtlasFactory
res = new(this, scale);
foreach (var fhm in this.fontHandleManagers)
res.InitialAddSubstance(fhm.NewSubstance(res));
res.InitialAddSubstance(fhm.NewSubstance(res));
unsafe
{
atlasPtr = (nint)res.Atlas.NativePtr;
@ -828,7 +814,7 @@ internal sealed partial class FontAtlasFactory
this.factory.Framework.RunOnFrameworkThread(
() =>
{
this.RebuildRecommend?.InvokeSafely();
this.RebuildRecommend.InvokeSafely();
switch (this.AutoRebuildMode)
{

View file

@ -79,13 +79,16 @@ internal abstract class FontHandle : IFontHandle
/// <param name="font">The font, locked during the call of <see cref="ImFontChanged"/>.</param>
public void InvokeImFontChanged(ILockedImFont font)
{
try
foreach (var d in Delegate.EnumerateInvocationList(this.ImFontChanged))
{
this.ImFontChanged?.Invoke(this, font);
}
catch (Exception e)
{
Log.Error(e, $"{nameof(this.InvokeImFontChanged)}: error");
try
{
d(this, font);
}
catch (Exception e)
{
Log.Error(e, $"{nameof(this.InvokeImFontChanged)}: error calling {d.Method.Name}");
}
}
}

View file

@ -151,7 +151,7 @@ internal class GamePrebakedFontHandle : FontHandle
}
if (suggestRebuild)
this.RebuildRecommend?.Invoke();
this.RebuildRecommend.InvokeSafely();
return handle;
}
@ -641,7 +641,7 @@ internal class GamePrebakedFontHandle : FontHandle
glyphIndex = (ushort)glyphs.Length;
glyphs.Add(default);
}
ref var g = ref glyphs[glyphIndex];
g = sourceGlyph;
if (fontScaleMode == FontScaleMode.SkipHandling)
@ -807,7 +807,7 @@ internal class GamePrebakedFontHandle : FontHandle
.GetCustomRectByIndex(rectId)
.NativePtr;
var widthAdjustment = this.BaseStyle.CalculateBaseWidthAdjustment(fdtFontHeader, fdtGlyph);
// Glyph is scaled at this point; undo that.
ref var glyph = ref glyphs[lookups[rc.GlyphId]];
glyph.X0 = this.BaseAttr.HorizontalOffset;
@ -822,7 +822,7 @@ internal class GamePrebakedFontHandle : FontHandle
this.gftp.GetTexFile(this.BaseAttr.TexPathFormat, fdtGlyph.TextureFileIndex);
var sourceBuffer = texFiles[fdtGlyph.TextureFileIndex].ImageData;
var sourceBufferDelta = fdtGlyph.TextureChannelByteIndex;
for (var y = 0; y < fdtGlyph.BoundingHeight; y++)
{
var sourcePixelIndex =
@ -830,11 +830,11 @@ internal class GamePrebakedFontHandle : FontHandle
sourcePixelIndex *= 4;
sourcePixelIndex += sourceBufferDelta;
var blend1 = horzBlend[fdtGlyph.CurrentOffsetY + y];
var targetOffset = ((rc.Y + y) * width) + rc.X;
for (var x = 0; x < rc.Width; x++)
pixels8[targetOffset + x] = 0;
targetOffset += horzShift[fdtGlyph.CurrentOffsetY + y];
if (blend1 == 0)
{