mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 13:14:17 +01:00
Resolve stale pointer issues (#1711)
* Resolve stale pointer issues * remove unncessary FrameworkOnBeforeUpdate --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
parent
1128d93fec
commit
2721e2df16
1 changed files with 8 additions and 18 deletions
|
|
@ -26,12 +26,11 @@ namespace Dalamud.Game.ClientState.Objects;
|
|||
#pragma warning disable SA1015
|
||||
[ResolveVia<IObjectTable>]
|
||||
#pragma warning restore SA1015
|
||||
internal sealed partial class ObjectTable : IServiceType, IObjectTable, IDisposable
|
||||
internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||
{
|
||||
private const int ObjectTableLength = 599;
|
||||
|
||||
private readonly ClientState clientState;
|
||||
private readonly Framework framework;
|
||||
private readonly CachedEntry[] cachedObjectTable = new CachedEntry[ObjectTableLength];
|
||||
|
||||
private readonly ObjectPool<Enumerator> multiThreadedEnumerators =
|
||||
|
|
@ -42,16 +41,14 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable, IDisposa
|
|||
private long nextMultithreadedUsageWarnTime;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private ObjectTable(ClientState clientState, Framework framework)
|
||||
private ObjectTable(ClientState clientState)
|
||||
{
|
||||
this.clientState = clientState;
|
||||
this.framework = framework;
|
||||
foreach (ref var e in this.cachedObjectTable.AsSpan())
|
||||
e = CachedEntry.CreateNew();
|
||||
for (var i = 0; i < this.frameworkThreadEnumerators.Length; i++)
|
||||
this.frameworkThreadEnumerators[i] = new(this, i);
|
||||
|
||||
framework.BeforeUpdate += this.FrameworkOnBeforeUpdate;
|
||||
Log.Verbose($"Object table address 0x{this.clientState.AddressResolver.ObjectTable.ToInt64():X}");
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +73,9 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable, IDisposa
|
|||
{
|
||||
_ = this.WarnMultithreadedUsage();
|
||||
|
||||
return index is >= ObjectTableLength or < 0 ? null : this.cachedObjectTable[index].ActiveObject;
|
||||
if (index is >= ObjectTableLength or < 0) return null;
|
||||
this.cachedObjectTable[index].Update(this.GetObjectAddressUnsafe(index));
|
||||
return this.cachedObjectTable[index].ActiveObject;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,12 +134,6 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable, IDisposa
|
|||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
this.framework.BeforeUpdate -= this.FrameworkOnBeforeUpdate;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool WarnMultithreadedUsage()
|
||||
{
|
||||
|
|
@ -161,12 +154,6 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable, IDisposa
|
|||
return true;
|
||||
}
|
||||
|
||||
private void FrameworkOnBeforeUpdate(IFramework unused)
|
||||
{
|
||||
for (var i = 0; i < ObjectTableLength; i++)
|
||||
this.cachedObjectTable[i].Update(this.GetObjectAddressUnsafe(i));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private unsafe nint GetObjectAddressUnsafe(int index) =>
|
||||
*(nint*)(this.clientState.AddressResolver.ObjectTable + (8 * index));
|
||||
|
|
@ -192,6 +179,9 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable, IDisposa
|
|||
|
||||
public unsafe void Update(nint address)
|
||||
{
|
||||
if (this.ActiveObject != null && address == this.ActiveObject.Address)
|
||||
return;
|
||||
|
||||
if (address == nint.Zero)
|
||||
{
|
||||
this.ActiveObject = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue