mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Fix memory ownership on AddFontFromImGuiHeapAllocatedMemory (#1651)
This commit is contained in:
parent
34ed07ef1f
commit
ea43d65636
2 changed files with 24 additions and 1 deletions
|
|
@ -185,6 +185,7 @@ internal sealed partial class FontAtlasFactory
|
|||
dataSize,
|
||||
debugTag);
|
||||
|
||||
var font = default(ImFontPtr);
|
||||
try
|
||||
{
|
||||
fontConfig.ThrowOnInvalidValues();
|
||||
|
|
@ -192,6 +193,7 @@ internal sealed partial class FontAtlasFactory
|
|||
var raw = fontConfig.Raw with
|
||||
{
|
||||
FontData = dataPointer,
|
||||
FontDataOwnedByAtlas = 1,
|
||||
FontDataSize = dataSize,
|
||||
};
|
||||
|
||||
|
|
@ -203,7 +205,7 @@ internal sealed partial class FontAtlasFactory
|
|||
|
||||
TrueTypeUtils.CheckImGuiCompatibleOrThrow(raw);
|
||||
|
||||
var font = this.NewImAtlas.AddFont(&raw);
|
||||
font = this.NewImAtlas.AddFont(&raw);
|
||||
|
||||
var dataHash = default(HashCode);
|
||||
dataHash.AddBytes(new(dataPointer, dataSize));
|
||||
|
|
@ -240,8 +242,23 @@ internal sealed partial class FontAtlasFactory
|
|||
}
|
||||
catch
|
||||
{
|
||||
if (!font.IsNull())
|
||||
{
|
||||
// Note that for both RemoveAt calls, corresponding destructors will be called.
|
||||
|
||||
var configIndex = this.data.ConfigData.FindIndex(x => x.DstFont == font.NativePtr);
|
||||
if (configIndex >= 0)
|
||||
this.data.ConfigData.RemoveAt(configIndex);
|
||||
|
||||
var index = this.Fonts.IndexOf(font);
|
||||
if (index >= 0)
|
||||
this.Fonts.RemoveAt(index);
|
||||
}
|
||||
|
||||
// ImFontConfig has no destructor, and does not free the data.
|
||||
if (freeOnException)
|
||||
ImGuiNative.igMemFree(dataPointer);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ internal sealed partial class FontAtlasFactory
|
|||
|
||||
private class FontAtlasBuiltData : IRefCountable
|
||||
{
|
||||
// Field for debugging.
|
||||
private static int numActiveInstances;
|
||||
|
||||
private readonly List<IDalamudTextureWrap> wraps;
|
||||
private readonly List<IFontHandleSubstance> substances;
|
||||
|
||||
|
|
@ -73,6 +76,9 @@ internal sealed partial class FontAtlasFactory
|
|||
|
||||
this.Garbage.Add(() => ImGuiNative.ImFontAtlas_destroy(atlasPtr));
|
||||
this.IsBuildInProgress = true;
|
||||
|
||||
Interlocked.Increment(ref numActiveInstances);
|
||||
this.Garbage.Add(() => Interlocked.Decrement(ref numActiveInstances));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue