From 9ef70c6c0c46fa506ddf6c93627b92efcc84d42e Mon Sep 17 00:00:00 2001 From: Selmar <3010534+Selmar@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:15:02 +0100 Subject: [PATCH] fix (BugSplatManager): unregister logMessageReceived on destruction Application.logMessageReceived is a static callback handler, which isn't reset when changing scenes or when exiting play mode if domain reloads are not enabled. When destroying the class without unregistering, e.g. due to scene change or existing play mode, the callback will then try to start a coroutine on the destroyed object. --- Runtime/Manager/BugSplatManager.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Runtime/Manager/BugSplatManager.cs b/Runtime/Manager/BugSplatManager.cs index c71889c..df3c3ca 100644 --- a/Runtime/Manager/BugSplatManager.cs +++ b/Runtime/Manager/BugSplatManager.cs @@ -33,13 +33,23 @@ private void Awake() if (registerLogMessageReceived) { - Application.logMessageReceived += (logMessage, stackTrace, type) => StartCoroutine(bugsplat.LogMessageReceived(logMessage, stackTrace, type)); + Application.logMessageReceived += LogMessageReceivedHandler; } - + if (dontDestroyManagerOnSceneLoad) { - DontDestroyOnLoad(this); + DontDestroyOnLoad(this); } } + + private void OnDestroy() + { + Application.logMessageReceived -= LogMessageReceivedHandler; + } + + void LogMessageReceivedHandler(string logMessage, string stackTrace, LogType type) + { + StartCoroutine(bugsplatRef.BugSplat.LogMessageReceived(logMessage, stackTrace, type)); + } } }