Slate Forums › Support › Avoiding null reference exceptions when changing scenes › Reply To: Avoiding null reference exceptions when changing scenes
I’ve been working through some runtime crashes that users have been submitting for my game, and at this point a large fraction of those crashed are null reference exceptions throw during the OnDestroy of various Slate actions clips. Here’s an example:
<pre style=”box-sizing: border-box; overflow: auto; font-size: 13px; line-height: 1.42857; font-family: Menlo, Monaco, Consolas, ‘Courier New’, monospace; padding: 9.5px; margin-top: 0px; margin-bottom: 10px; word-break: keep-all; overflow-wrap: break-word; background-color: #f5f5f5; border: 1px solid #cccccc; border-radius: 4px; white-space: pre-wrap;”>Slate.ActionClips.FinalIK.AnimateBipedLimb.OnUpdate (System.Single time) (at <6f0ca905826e4267a81d4771ab148b4b>:0)
Slate.ActionClip.OnUpdate (System.Single time, System.Single previousTime) (at <6f0ca905826e4267a81d4771ab148b4b>:0)
Slate.ActionClip.Slate.IDirectable.Update (System.Single time, System.Single previousTime) (at <6f0ca905826e4267a81d4771ab148b4b>:0)
Slate.StartTimePointer.Slate.IDirectableTimePointer.TriggerBackward (System.Single currentTime, System.Single previousTime) (at <6f0ca905826e4267a81d4771ab148b4b>:0)
Slate.Cutscene.Internal_SamplePointers (System.Single currentTime, System.Single previousTime) (at <6f0ca905826e4267a81d4771ab148b4b>:0)
UnityEngine.Debug:LogException(Exception)
Slate.Cutscene:Internal_SamplePointers(Single, Single)
Slate.Cutscene:Sample(Single)
Slate.Cutscene:Stop(StopMode)
Slate.Cutscene:OnDestroy()
What’s tricky about this is that I believe I’ve already calling Stop() on all cutscenes whenever I do something meaningful, like changing scenes, or anything else I can think of that would cause cutscenes to be destroyed.
What’s the reasoning for rewinding an active cutscene during OnDestroy? It seems pretty risky to me. I think the general cause of the exception is the same as I was seeing before: ‘actor’ tends to be null in the action clips. Do you have an example of what other problems might occur if a cutscene isn’t rewound during OnDestroy?
I’m not sure what else I can call to prevent Slate from generating errors. I’m also not sure whether these errors are legitimate, or whether they only occur as a side-effect of some other crash that brings down the application. In any case, at this point, I feel like I need to manually bullet-proof the slate action clips to avoid trying to access ‘actor’ when it’s null. But it would be really helpful if this was somehow automated.