From 8251cc2057468229afc9b3b46eaebc9ac7ddca43 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sun, 14 Nov 2021 01:18:53 +0700 Subject: [PATCH] Change Signal to disconnect bad receivers quicker --- sources/Events/Signal.uc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sources/Events/Signal.uc b/sources/Events/Signal.uc index b146b45..c28179a 100644 --- a/sources/Events/Signal.uc +++ b/sources/Events/Signal.uc @@ -183,15 +183,26 @@ protected function Finalizer() * Must be a properly allocated `AcediaObject`. * @return New `Slot` object that will be connected to the caller `Signal` if * provided `receiver` is correct. Guaranteed to have class - * `relatedSlotClass`. + * `relatedSlotClass`. Guaranteed to not be `none` if allocated `receiver` + * is provided. */ public final function Slot NewSlot(AcediaObject receiver) { local Slot newSlot; + if (receiver == none) { + return none; + } newSlot = Slot(_.memory.Allocate(relatedSlotClass)); - newSlot.Initialize(self, receiver); - AddSlot(newSlot, receiver); - return newSlot; + if (newSlot.Initialize(self, receiver)) + { + AddSlot(newSlot, receiver); + return newSlot; + } + newSlot.FreeSelf(); + if (!receiver.IsAllocated()) { + Disconnect(receiver); + } + return none; } /**