From b299ed32469f59467eb00d6fc3f7c329cbd7bffc Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 9 Jun 2023 23:34:55 +0200 Subject: [PATCH] Add more assertions to tests build --- Source/Engine/Content/Assets/Model.cpp | 2 +- Source/Engine/Content/Content.cpp | 4 ++-- Source/Engine/Level/Prefabs/PrefabManager.cpp | 21 ++++++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Source/Engine/Content/Assets/Model.cpp b/Source/Engine/Content/Assets/Model.cpp index 9319f2667..5a008645d 100644 --- a/Source/Engine/Content/Assets/Model.cpp +++ b/Source/Engine/Content/Assets/Model.cpp @@ -1012,7 +1012,7 @@ Asset::LoadResult Model::load() } } -#if BUILD_DEBUG || BUILD_DEVELOPMENT +#if !BUILD_RELEASE // Validate LODs for (int32 lodIndex = 1; lodIndex < LODs.Count(); lodIndex++) { diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index e58aa458d..c28ed61ef 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -304,7 +304,7 @@ bool Content::GetAssetInfo(const StringView& path, AssetInfo& info) auto storage = ContentStorageManager::GetStorage(path); if (storage) { -#if BUILD_DEBUG +#if BUILD_DEBUG || FLAX_TESTS ASSERT(storage->GetPath() == path); #endif @@ -904,7 +904,7 @@ bool Content::IsAssetTypeIdInvalid(const ScriptingTypeHandle& type, const Script if (!type || !assetType) return false; -#if BUILD_DEBUG +#if BUILD_DEBUG || FLAX_TESTS // Peek types for debugging const auto& typeObj = type.GetType(); const auto& assetTypeObj = assetType.GetType(); diff --git a/Source/Engine/Level/Prefabs/PrefabManager.cpp b/Source/Engine/Level/Prefabs/PrefabManager.cpp index 4c91bae25..cc42967a4 100644 --- a/Source/Engine/Level/Prefabs/PrefabManager.cpp +++ b/Source/Engine/Level/Prefabs/PrefabManager.cpp @@ -189,26 +189,26 @@ Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, DictionaryGetParent() == nullptr) { - sceneObjects->At(i) = nullptr; LOG(Warning, "Scene object {0} {1} has missing parent object after load. Removing it.", obj->GetID(), obj->ToString()); + sceneObjects->At(i) = nullptr; obj->DeleteObject(); continue; } -#if USE_EDITOR && !BUILD_RELEASE +#if (USE_EDITOR && !BUILD_RELEASE) || FLAX_TESTS // Check for not being added to the parent (eg. invalid setup events fault on registration) auto actor = dynamic_cast(obj); auto script = dynamic_cast(obj); if (obj->GetParent() == obj || (actor && !actor->GetParent()->Children.Contains(actor)) || (script && !script->GetParent()->Scripts.Contains(script))) { - sceneObjects->At(i) = nullptr; LOG(Warning, "Scene object {0} {1} has invalid parent object linkage after load. Removing it.", obj->GetID(), obj->ToString()); + sceneObjects->At(i) = nullptr; obj->DeleteObject(); continue; } #endif -#if USE_EDITOR && BUILD_DEBUG +#if (USE_EDITOR && BUILD_DEBUG) || FLAX_TESTS // Check for being added to parent not from spawned prefab (eg. invalid parentId linkage fault) bool hasParentInInstance = false; for (int32 j = 0; j < sceneObjects->Count(); j++) @@ -221,11 +221,22 @@ Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, DictionaryAt(i) = nullptr; LOG(Warning, "Scene object {0} {1} has invalid parent object after load. Removing it.", obj->GetID(), obj->ToString()); + sceneObjects->At(i) = nullptr; obj->DeleteObject(); continue; } + +#if FLAX_TESTS + // Perform extensive validation of the prefab instance structure + if (actor && actor->HasActorInHierarchy(actor)) + { + LOG(Warning, "Scene object {0} {1} has invalid hierarchy after load. Removing it.", obj->GetID(), obj->ToString()); + sceneObjects->At(i) = nullptr; + obj->DeleteObject(); + continue; + } +#endif #endif }