Validator: Fixed issue, where scene wouldn't unload, if an exception is thrown

This commit is contained in:
Anders Ejlersen 2026-05-27 19:24:07 +02:00
parent 3802ca557c
commit 9dd45f536e

View file

@ -178,13 +178,13 @@ namespace Module.ProjectValidator.Editor
var rootObjects = new List<GameObject>();
for (var i = 0; i < assets.Length; i++)
{
try
{
var assetPath = AssetDatabase.GetAssetPath(assets[i]);
var scene = SceneManager.GetSceneByPath(assetPath);
var isLoaded = scene.isLoaded;
try
{
if (!isLoaded)
scene = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Additive);
@ -194,14 +194,16 @@ namespace Module.ProjectValidator.Editor
{
ValidateGameObject(rootObjects[j], string.Empty, report, true);
}
if (!isLoaded)
EditorSceneManager.CloseScene(scene, true);
}
catch (Exception e)
{
Debug.LogException(e);
}
finally
{
if (!isLoaded && scene.isLoaded)
EditorSceneManager.CloseScene(scene, true);
}
}
}