From 21836cf62f287a56e0dcaacb7c3b20025e32ec2c Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:18:56 -0700 Subject: [PATCH] fix: Fixes massive capacity bug with pooled ref queue/list (#1865) --- Projects/Server/Collections/PooledRefList.cs | 5 ++-- Projects/Server/Collections/PooledRefQueue.cs | 2 +- .../UOContent/Accounting/AccountHandler.cs | 23 ------------------- Projects/UOContent/Mobiles/PlayerMobile.cs | 20 +++++++++++++--- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Projects/Server/Collections/PooledRefList.cs b/Projects/Server/Collections/PooledRefList.cs index 8aff2f7b34..f17476a44b 100644 --- a/Projects/Server/Collections/PooledRefList.cs +++ b/Projects/Server/Collections/PooledRefList.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using Server.Buffers; namespace Server.Collections; @@ -152,14 +151,14 @@ public int Capacity if (_items.Length > 0) { - Clear(); + Array.Clear(_items); ArrayPool.Return(_items); } _items = newItems; } else { - Clear(); + Array.Clear(_items); ArrayPool.Return(_items); _items = s_emptyArray; } diff --git a/Projects/Server/Collections/PooledRefQueue.cs b/Projects/Server/Collections/PooledRefQueue.cs index cef14806ac..deddb67de1 100644 --- a/Projects/Server/Collections/PooledRefQueue.cs +++ b/Projects/Server/Collections/PooledRefQueue.cs @@ -305,7 +305,7 @@ private void SetCapacity(int capacity) if (_array.Length > 0) { - Clear(); + Array.Clear(_array); (_mt ? ArrayPool.Shared : STArrayPool.Shared).Return(_array); } diff --git a/Projects/UOContent/Accounting/AccountHandler.cs b/Projects/UOContent/Accounting/AccountHandler.cs index a8acf407f3..12f9a96474 100644 --- a/Projects/UOContent/Accounting/AccountHandler.cs +++ b/Projects/UOContent/Accounting/AccountHandler.cs @@ -2,19 +2,10 @@ using System.Collections.Generic; using System.Net; using Server.Accounting; -using Server.Engines.CannedEvil; using Server.Engines.Help; -using Server.Engines.PlayerMurderSystem; -using Server.Engines.Virtues; using Server.Logging; using Server.Network; using Server.Regions; -using Server.Spells.Fifth; -using Server.Spells.First; -using Server.Spells.Mysticism; -using Server.Spells.Necromancy; -using Server.Spells.Ninjitsu; -using Server.Spells.Second; namespace Server.Misc; @@ -236,20 +227,6 @@ public static void DeleteRequest(NetState state, int index) m.Delete(); - StaminaSystem.OnPlayerDeleted(m); - JusticeVirtue.OnPlayerDeleted(m); - PlayerMurderSystem.OnPlayerDeleted(m); - ChampionTitleSystem.OnPlayerDeleted(m); - - // Spells - MagicReflectSpell.EndReflect(m); - ReactiveArmorSpell.EndArmor(m); - ProtectionSpell.EndProtection(m); - StoneFormSpell.RemoveEffects(m); - AnimateDeadSpell.RemoveEffects(m); - SummonFamiliarSpell.RemoveEffects(m); - AnimalForm.RemoveLastAnimalForm(m); - state.SendCharacterListUpdate(acct); return; } diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index 50956bc8cc..806cb8cd2e 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -28,9 +28,12 @@ using Server.Spells; using Server.Spells.Bushido; using Server.Spells.Fifth; +using Server.Spells.First; using Server.Spells.Fourth; +using Server.Spells.Mysticism; using Server.Spells.Necromancy; using Server.Spells.Ninjitsu; +using Server.Spells.Second; using Server.Spells.Seventh; using Server.Spells.Sixth; using Server.Spells.Spellweaving; @@ -3382,14 +3385,25 @@ public override void OnAfterDelete() base.OnAfterDelete(); var faction = Faction.Find(this); - faction?.RemoveMember(this); MLQuestSystem.HandleDeletion(this); - BaseHouse.HandleDeletion(this); - DisguisePersistence.RemoveTimer(this); + + StaminaSystem.OnPlayerDeleted(this); + JusticeVirtue.OnPlayerDeleted(this); + PlayerMurderSystem.OnPlayerDeleted(this); + ChampionTitleSystem.OnPlayerDeleted(this); + + // Spells + MagicReflectSpell.EndReflect(this); + ReactiveArmorSpell.EndArmor(this); + ProtectionSpell.EndProtection(this); + StoneFormSpell.RemoveEffects(this); + AnimateDeadSpell.RemoveEffects(this); + SummonFamiliarSpell.RemoveEffects(this); + AnimalForm.RemoveLastAnimalForm(this); } public override void GetProperties(IPropertyList list)