You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm seeing some exceptions caused by smartparts due to the Invoke call in onVesselChange on a part that I think is getting destroyed before the invoked function is finally called.
[ERR 11:06:30.073] Exception handling event onVesselChange in class Timer:System.NullReferenceException
at (wrapper managed-to-native) UnityEngine.MonoBehaviour.InvokeDelayed(UnityEngine.MonoBehaviour,string,single,single)
at UnityEngine.MonoBehaviour.Invoke (System.String methodName, System.Single time) [0x00001] in <2425394cf09642369e2109953e31f62b>:0
at Lib.Timer.onVesselChange (Vessel newVessel) [0x0001c] in <486db0c7375c47f7909494a00dbf2916>:0
at EventData`1[T].Fire (T data) [0x000b0] in <4deecb19beb547f19b1ff89b4c59bd84>:0
[EXC 11:06:30.074] NullReferenceException
UnityEngine.MonoBehaviour.Invoke (System.String methodName, System.Single time) (at <2425394cf09642369e2109953e31f62b>:0)
Lib.Timer.onVesselChange (Vessel newVessel) (at <486db0c7375c47f7909494a00dbf2916>:0)
EventData`1[T].Fire (T data) (at <4deecb19beb547f19b1ff89b4c59bd84>:0)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
EventData`1:Fire(Vessel)
FlightGlobals:setActiveVessel(Vessel, Boolean, Boolean)
FlightGlobals:ForceSetActiveVessel(Vessel)
BDArmory.UI.LoadedVesselSwitcher:ForceSwitchVessel(Vessel)
BDArmory.UI.LoadedVesselSwitcher:UpdateCamera()
BDArmory.UI.LoadedVesselSwitcher:Update()
booldelayedFunctionRunning=false;// If required for exclusivity of running delayedFunction.voidonMyEvent(){if(!delayedFunctionRunning){StartCoroutine(delayedFunction(0.25f));// Coroutines get stopped automatically if the instance is destroyed.}}IEnumeratordelayedFunction(floatdelay){delayedFunctionRunning=true;yieldreturnnewWaitForSeconds(delay);if(part==null)yieldbreak;// The part has been destroyed.// Do stuff.delayedFunctionRunning=false;}
The text was updated successfully, but these errors were encountered:
Hi,
I'm seeing some exceptions caused by smartparts due to the
Invoke
call inonVesselChange
on a part that I think is getting destroyed before the invoked function is finally called.Incidentally, the Unity documentation recommends using coroutines instead of invoke (https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html), which avoids these kinds of issues.
The pattern (in case you're unaware of it) is:
The text was updated successfully, but these errors were encountered: