-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ForceUnloadAllScenes on Application Quit causes crash on Android #301
Comments
The comment above ProjectKernel.OnApplicationQuit explains the reasoning. Basically, when a scene is unloaded, or the application is closed, Unity destroys all the game objects in an unpredictable order. Also, OnDestroy does not use Unity's Script Execution Order, so there's no way to control that either, except by exploiting the fact that Unity does at least destroy the root level transforms first before children. However, if you do need a predictable destruction order, you can use Zenject's IDisposable bindings. You can also use this with MonoBehaviours in addition to normal C# classes, as long as you also check "ParentNewObjectsUnderRoot" on each scene context (to ensure the SceneContext is destroyed before children since as mentioned above Unity will at least destroy game objects top-down). However, in order to get this same predictable destruction order to work when using Unity's multi-scene editing, we have to explicitly delete each scene context in reverse order that they were loaded. This is because Unity also doesn't unload scenes in any predictable order either. If you aren't using multiple scenes, or if you don't care about predictable destruction order, then there's no risk in removing that behaviour from ProjectKernel |
Thanks, I forgot about that comment, sorry. My guess is that the native side of Unity is trying to send a message to a GameObject that was destroyed by the scenes unload call. Also, Unity suggests to not use DestroyImmediate outside the editor, maybe the problem's there? |
Good point. Can you try changing to Destroy and seeing if that fixes it? |
I'll try tomorrow morning and let you know, thanks |
I have a feeling that we were using DestroyImmediate for a reason there though. I am guessing that Unity recommends against it so that they can destroy objects in batches at the end of the frame, so Destroy probably just queues it to be destroyed. In this case though it is probably already queued for destroy so that might not actually have any effect and defeat the purpose of the whole thing |
Hello, |
Ok thanks for letting me know - I will take a look |
This piece of code within OnApplicationQuit() method caused many crashes of my Unity editor when exiting play mode. I can confirm that replacing by Destroy fixes the issue, but with error
Anyways, I am really happy to have it solved, it was really, and I mean really annoying. |
Fixed by making this behaviour optional and off by default (togglable in zenject settings) |
Hello,
We noticed in our project that this code in ProjectKernel.cs
causes a native crash on some Android devices on app quit (happens at least on Unity 5.6.2 and Unity 2017). The crash is a classic Unity SIGSEGV with the following code addresses:
The libunity.so calls point to this stacktrace:
Removing the OnApplicationQuit solves the issue for us, what is the reason for unloading scenes when the application is quitting anyway?
The text was updated successfully, but these errors were encountered: