Repository navigation
Conversation
When play mode exits, NDMF closes the preview scene at ExitingPlayMode. Unity then restores the scene backups in EditorSceneManager::RestoreSceneBackups and sets the active scene while some backups still load. This fires activeSceneChangedInEditMode, and the handler calls GetPreviewScene, which opens the preview scene additively with EditorSceneManager.OpenScene in the middle of the restore. That nested load runs UnloadUnusedAssetsOperation while a restored scene is only half loaded, and the editor can segfault in Transform::MainThreadCleanup. The handler now defers GetPreviewScene with EditorApplication.delayCall, so the preview scene opens after the restore is complete. Seen four times in one month on Unity 2022.3.22f1 with NDMF 1.15.0-beta.5.
Author
|
Closing this. A later play mode exit with this change crashed in the same asset cleanup inside RestoreSceneBackups, with no NDMF frame on the stack, so this change does not fix the crash. Sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Source
Playtest: Unity 2022.3.22f1, VRChat avatar project, NDMF 1.15.0-beta.5, four scenes loaded additively, Enter Play Mode Options on. The handler is unchanged on
main.Symptom
Root cause
NDMFPreviewSceneManagercloses the preview scene atPlayModeStateChange.ExitingPlayMode(Editor/PreviewSystem/Rendering/NDMFPreviewSceneManager.cs:86-87).EditorSceneManager::RestoreSceneBackups. When a backup finishes integration, Unity sets the active scene, and this firesEditorSceneManager.activeSceneChangedInEditMode.GetPreviewScene(). The preview scene is no longer valid, so it callsEditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive)at line 144, in the middle of the restore.UnloadUnusedAssetsOperation. ItsGarbageCollectSharedAssetsstep deletes objects while a restored scene is only half loaded, and the editor crashes inTransform::MainThreadCleanup.Fix
activeSceneChangedInEditModehandler now defersGetPreviewScene()withEditorApplication.delayCall. The preview scene opens on the next editor update, after Unity has finished the restore.GetPreviewScene()returns early when the preview scene is already valid, so several deferred calls from one restore open the scene only once.For existing users, the preview scene now opens one editor update after any active scene change, including normal scene switches in edit mode, instead of inside the event.
Evidence
The unload after
0.backupin the second log is part of Unity's own restore. NDMF does not callUnloadUnusedAssets, and the preview scene has not opened yet at that point.Confidence
Medium. The stack shows the crash inside the nested
OpenScenecall from this handler, and the fix moves that call out of the restore. The limit: I tested the fix on one play mode exit only. The crash is intermittent, so this shows the new load order, not a measured crash rate. I did not add a unit test, because the crash needs a real play mode exit with scene backups.