Fixes issue where getting battle from a pokemon could result in battle being in a deleted state.

This commit is contained in:
Deukhoofd 2021-01-31 12:53:35 +01:00
parent 9f30f411cc
commit cbe5747d04
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 3 additions and 3 deletions

View File

@ -145,7 +145,7 @@ namespace PkmnLibSharp.Battling
get
{
var ptr = Creaturelib.Generated.Creature.GetBattle(Ptr);
if (_battle != null && _battle.Ptr == ptr) return _battle;
if (_battle != null && !_battle.IsDeleted && _battle.Ptr == ptr) return _battle;
if (TryResolvePointer(ptr, out _battle))
return _battle;
_battle = Constructor.Active.ConstructBattle(ptr);
@ -157,7 +157,7 @@ namespace PkmnLibSharp.Battling
get
{
var ptr = Creaturelib.Generated.Creature.GetBattleSide(Ptr);
if (_battleSide != null && _battleSide.Ptr == ptr) return _battleSide;
if (_battleSide != null && !_battleSide.IsDeleted && _battleSide.Ptr == ptr) return _battleSide;
if (TryResolvePointer(ptr, out _battleSide))
return _battleSide;
_battleSide = new BattleSide(ptr);

View File

@ -21,7 +21,7 @@ namespace PkmnLibSharp.Utilities
}
}
protected bool IsDeleted { get; private set; } = false;
public bool IsDeleted { get; private set; } = false;
private static readonly ConcurrentDictionary<IntPtr, WeakReference<PointerWrapper>> Cached =
new ConcurrentDictionary<IntPtr, WeakReference<PointerWrapper>>();