Ensure pointers aren't used anymore when their parents are being deleted and they should be deleted themselves.
This commit is contained in:
parent
9bcfdf7791
commit
eb99fc5661
|
@ -143,6 +143,12 @@ namespace PkmnLibSharp.Library
|
|||
{
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
_moves?.MarkAsDeleted();
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
SpeciesVariant.Destruct(Ptr);
|
||||
|
|
|
@ -63,6 +63,15 @@ namespace PkmnLibSharp.Library.Items
|
|||
{
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var item in _cache)
|
||||
{
|
||||
item.Value.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
Creatureliblibrary.Generated.ItemLibrary.Destruct(Ptr);
|
||||
|
|
|
@ -66,6 +66,15 @@ namespace PkmnLibSharp.Library.Moves
|
|||
{
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var moveData in _cache)
|
||||
{
|
||||
moveData.Value.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
AttackLibrary.Destruct(Ptr);
|
||||
|
|
|
@ -58,5 +58,14 @@ namespace PkmnLibSharp.Library
|
|||
{
|
||||
Pkmnlib.Generated.NatureLibrary.Destruct(Ptr);
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var nature in _cache)
|
||||
{
|
||||
nature.Value.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -133,5 +133,17 @@ namespace PkmnLibSharp.Library
|
|||
{
|
||||
Pkmnlib.Generated.PokemonLibrary.Destruct(Ptr);
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
_settings?.MarkAsDeleted();
|
||||
_species?.MarkAsDeleted();
|
||||
_moves?.MarkAsDeleted();
|
||||
_items?.MarkAsDeleted();
|
||||
_growthRateLibrary?.MarkAsDeleted();
|
||||
_typeLibrary?.MarkAsDeleted();
|
||||
_natureLibrary?.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -84,6 +84,15 @@ namespace PkmnLibSharp.Library
|
|||
return s;
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var forme in _formes)
|
||||
{
|
||||
forme.Value.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DeletePtr()
|
||||
{
|
||||
PokemonSpecies.Destruct(Ptr);
|
||||
|
|
|
@ -67,5 +67,14 @@ namespace PkmnLibSharp.Library
|
|||
{
|
||||
Creatureliblibrary.Generated.SpeciesLibrary.Destruct(Ptr);
|
||||
}
|
||||
|
||||
protected internal override void MarkAsDeleted()
|
||||
{
|
||||
base.MarkAsDeleted();
|
||||
foreach (var species in _cache)
|
||||
{
|
||||
species.Value.MarkAsDeleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,4 +22,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Battling" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PkmnLibSharp.Utilities
|
||||
{
|
||||
|
@ -70,9 +68,14 @@ namespace PkmnLibSharp.Utilities
|
|||
{
|
||||
if (_isDeleted)
|
||||
return;
|
||||
Cached.TryRemove(Ptr, out _);
|
||||
DeletePtr();
|
||||
MarkAsDeleted();
|
||||
}
|
||||
|
||||
protected internal virtual void MarkAsDeleted()
|
||||
{
|
||||
_isDeleted = true;
|
||||
Cached.TryRemove(_ptr, out _);
|
||||
}
|
||||
|
||||
protected bool Equals(PointerWrapper other)
|
||||
|
|
Loading…
Reference in New Issue