From c19658a9ddc32baf248269e92390dba952ea788e Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Sun, 11 May 2025 23:13:06 -0500 Subject: [PATCH] Fixed Crashing and edge cases --- src/src/core/functions/ProjectManager.cpp | 3 +-- src/src/core/utils/AssetManager.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/src/core/functions/ProjectManager.cpp b/src/src/core/functions/ProjectManager.cpp index 3d9d196..724d933 100644 --- a/src/src/core/functions/ProjectManager.cpp +++ b/src/src/core/functions/ProjectManager.cpp @@ -164,7 +164,6 @@ void FileExplorer::Show(bool* p_open) entries.push_back(e); } - // Sort std::sort(entries.begin(), entries.end(), [&](auto &a, auto &b) { if (sortMode == 1) { bool da = a.is_directory(), db = b.is_directory(); @@ -231,7 +230,7 @@ void FileExplorer::Show(bool* p_open) break; } clicked = ImGui::Button( - (std::string("##entry") + label).c_str(), + (label + std::string("##entry") + label).c_str(), ImVec2(iconSize, iconSize)); } diff --git a/src/src/core/utils/AssetManager.cpp b/src/src/core/utils/AssetManager.cpp index 980d848..14cb563 100644 --- a/src/src/core/utils/AssetManager.cpp +++ b/src/src/core/utils/AssetManager.cpp @@ -792,14 +792,25 @@ void PrefabAssetInfo::ReloadFromYAML() std::shared_ptr PrefabAssetInfo::Instantiate() const { - if (!prefabYAML || !prefabYAML.IsMap()) - { - Logger::LogError("[PrefabAsset] Cannot instantiate: prefab YAML is invalid."); + if (!prefabYAML || !prefabYAML.IsMap()) { + Logger::LogError("Cannot instantiate '%s': invalid YAML.", prefabName.c_str()); + return nullptr; + } + + static thread_local std::unordered_set s_instantiating; + + if (!s_instantiating.insert(uaid).second) { + Logger::LogError( + "Recursive instantiation detected for prefab '%s' (UAID=%llu).", + prefabName.c_str(), (unsigned long long)uaid + ); return nullptr; } auto newObj = std::make_shared(prefabName); newObj->Load(prefabYAML); + + s_instantiating.erase(uaid); return newObj; }