Fixes issue where getting battle from a pokemon could result in battle being in a deleted state.
This commit is contained in:
parent
9f30f411cc
commit
cbe5747d04
|
@ -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);
|
||||
|
|
|
@ -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>>();
|
||||
|
|
Loading…
Reference in New Issue