From 8ee77fb212e76d744f36f828bc2c4bf4c17c342b Mon Sep 17 00:00:00 2001 From: bd_ Date: Sat, 5 Oct 2024 14:48:42 -0700 Subject: [PATCH] fix: exception when scene is unloaded Closes: #436 --- CHANGELOG.md | 3 +-- Editor/PreviewSystem/Rendering/NDMFPreviewSceneManager.cs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa451cc..3cb4a47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Fixed -- [#435] Fixed an issue where `File -> Save As` could break due to the internal preview scene becoming selected +- [#438] Fixed an issue where exceptions would be thrown when scenes are unloaded ### Changed @@ -23,7 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.5.3] - [2024-10-03] ### Fixed - - [#435] Fixed an issue where `File -> Save As` could break due to the internal preview scene becoming selected ## [1.5.2] - [2024-10-02] diff --git a/Editor/PreviewSystem/Rendering/NDMFPreviewSceneManager.cs b/Editor/PreviewSystem/Rendering/NDMFPreviewSceneManager.cs index a2be569..ef4efd1 100644 --- a/Editor/PreviewSystem/Rendering/NDMFPreviewSceneManager.cs +++ b/Editor/PreviewSystem/Rendering/NDMFPreviewSceneManager.cs @@ -62,7 +62,7 @@ private static void Init() for (var i = 0; i < sceneCount; i++) { var scene = SceneManager.GetSceneAt(i); - if (scene == _previewScene) continue; + if (scene == _previewScene || !scene.isLoaded || !scene.IsValid()) continue; SceneManager.SetActiveScene(scene); found = true; @@ -71,7 +71,7 @@ private static void Init() if (!found) { - // Unload the preview scene if it's the only one left + // Unload the preview scene if it's the only valid/loaded scene left EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); ResetPreviewScene();