From f01971a7d7667ccb10eb7448077a1144cc6a04b0 Mon Sep 17 00:00:00 2001 From: AtmoOmen Date: Thu, 12 Feb 2026 16:54:55 +0800 Subject: [PATCH] fix Addon/AgentLifyCycle unreg (cherry picked from commit 29e1715ff589b9dddf5a747b8655ea382e08cf58) --- Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs | 6 ++++++ Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs | 5 +++++ Dalamud/Game/Agent/AgentLifecycle.cs | 6 ++++++ Dalamud/Game/Agent/AgentLifecycleEventListener.cs | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs b/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs index 6520ee4cf..2e5439ed0 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs @@ -94,6 +94,8 @@ internal unsafe class AddonLifecycle : IInternalDisposableService /// The listener to unregister. internal void UnregisterListener(AddonLifecycleEventListener listener) { + listener.IsRequestedToClear = true; + if (this.isInvokingListeners) { this.framework.RunOnTick(() => this.UnregisterListenerMethod(listener)); @@ -122,6 +124,8 @@ internal unsafe class AddonLifecycle : IInternalDisposableService { foreach (var listener in globalListeners) { + if (listener.IsRequestedToClear) continue; + try { listener.FunctionDelegate.Invoke(eventType, args); @@ -138,6 +142,8 @@ internal unsafe class AddonLifecycle : IInternalDisposableService { foreach (var listener in addonListener) { + if (listener.IsRequestedToClear) continue; + try { listener.FunctionDelegate.Invoke(eventType, args); diff --git a/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs b/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs index fc82e0582..38c081e65 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonLifecycleEventListener.cs @@ -35,4 +35,9 @@ internal class AddonLifecycleEventListener /// Gets the delegate this listener invokes. /// public IAddonLifecycle.AddonEventDelegate FunctionDelegate { get; init; } + + /// + /// Gets or sets if the listener is requested to be cleared. + /// + internal bool IsRequestedToClear { get; set; } } diff --git a/Dalamud/Game/Agent/AgentLifecycle.cs b/Dalamud/Game/Agent/AgentLifecycle.cs index 45f0dec5c..1c895f9da 100644 --- a/Dalamud/Game/Agent/AgentLifecycle.cs +++ b/Dalamud/Game/Agent/AgentLifecycle.cs @@ -107,6 +107,8 @@ internal unsafe class AgentLifecycle : IInternalDisposableService /// The listener to unregister. internal void UnregisterListener(AgentLifecycleEventListener listener) { + listener.IsRequestedToClear = true; + if (this.isInvokingListeners) { this.framework.RunOnTick(() => this.UnregisterListenerMethod(listener)); @@ -135,6 +137,8 @@ internal unsafe class AgentLifecycle : IInternalDisposableService { foreach (var listener in globalListeners) { + if (listener.IsRequestedToClear) continue; + try { listener.FunctionDelegate.Invoke(eventType, args); @@ -151,6 +155,8 @@ internal unsafe class AgentLifecycle : IInternalDisposableService { foreach (var listener in agentListener) { + if (listener.IsRequestedToClear) continue; + try { listener.FunctionDelegate.Invoke(eventType, args); diff --git a/Dalamud/Game/Agent/AgentLifecycleEventListener.cs b/Dalamud/Game/Agent/AgentLifecycleEventListener.cs index 91f8aa3d3..592c126ba 100644 --- a/Dalamud/Game/Agent/AgentLifecycleEventListener.cs +++ b/Dalamud/Game/Agent/AgentLifecycleEventListener.cs @@ -35,4 +35,9 @@ public class AgentLifecycleEventListener /// Gets the delegate this listener invokes. /// public IAgentLifecycle.AgentEventDelegate FunctionDelegate { get; init; } + + /// + /// Gets or sets if the listener is requested to be cleared. + /// + internal bool IsRequestedToClear { get; set; } }