From 8cb3b42de2d1e6474ee862ed70d410d8dc5787fc Mon Sep 17 00:00:00 2001 From: BoilTask Date: Mon, 13 Apr 2026 11:08:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9AGC=E6=97=B6=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=B8=85=E7=90=86=E5=85=B3=E8=81=94Delegate=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E5=A4=B1=E6=95=88=E7=9A=84Handle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Private/Registries/DelegateRegistry.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Plugins/UnLua/Source/UnLua/Private/Registries/DelegateRegistry.cpp b/Plugins/UnLua/Source/UnLua/Private/Registries/DelegateRegistry.cpp index aa59a3433..f9292cf30 100644 --- a/Plugins/UnLua/Source/UnLua/Private/Registries/DelegateRegistry.cpp +++ b/Plugins/UnLua/Source/UnLua/Private/Registries/DelegateRegistry.cpp @@ -41,29 +41,43 @@ namespace UnLua void FDelegateRegistry::OnPostGarbageCollect() { + TSet InvalidDelegates; TArray> InvalidPairs; for (auto& Pair : Delegates) { if (!Pair.Value.Owner.IsValid()) + { InvalidPairs.Add(Pair); + InvalidDelegates.Add(Pair.Key); + } } for (int i = 0; i < InvalidPairs.Num(); i++) { const auto& Pair = InvalidPairs[i]; + if (Pair.Value.bIsMulticast) + { Clear(Pair.Key); + } else + { Unbind(Pair.Key); + } Delegates.Remove(Pair.Key); + if (Pair.Value.bDeleteOnRemove) + { delete (FScriptDelegate*)Pair.Key; + } } TArray ToRemove; for (auto& Pair : CachedHandlers) { - if (Pair.Key.SelfObject.IsStale()) + if (Pair.Key.SelfObject.IsStale() + || !Pair.Value.IsValid() + || InvalidDelegates.Contains(Pair.Value->Delegate)) { ToRemove.Add(Pair.Key); Env->AutoObjectReference.Remove(Pair.Value.Get());