-
Notifications
You must be signed in to change notification settings - Fork 28
Closed
Description
It looks like there's an issue with the order of operations when it comes to IDisposable objects on a scene switch. The EventCallerContainerExtension.OnUnregister() call currently looks like this:
public void OnUnregister(IInjectionContainer container) {
container.afterAddBinding -= this.OnAfterAddBinding;
container.bindingResolution -= this.OnBindingResolution;
disposable.Clear();
updateable.Clear();
lateUpdateable.Clear();
fixedUpdateable.Clear();
focusable.Clear();
pausable.Clear();
quitable.Clear();
if (behaviour != null && behaviour.gameObject != null) {
MonoBehaviour.DestroyImmediate(behaviour.gameObject);
}
behaviour = null;
}
The problem is that when I switch scenes the OnUnregister() method appears to run before EventCallerBehaviour.OnDestroy() is run. This means the disposable.Clear() call occurs before the MonoBehaviour.DestroyImmediate() call, and THAT means the EventCallerBehaviour.OnDestroy() looks at an empty extension.disposable list and doesn't dispose of anything.
My temporary solution has been to change OnUnregister() to destroy the object before clearing the list:
public void OnUnregister(IInjectionContainer container) {
container.afterAddBinding -= this.OnAfterAddBinding;
container.bindingResolution -= this.OnBindingResolution;
if (behaviour != null && behaviour.gameObject != null) {
MonoBehaviour.DestroyImmediate(behaviour.gameObject);
}
disposable.Clear();
[...]
}
I'm not sure what ramifications this has on the overall system though.