diff --git a/src/core/systems/AssetManager.cpp b/src/core/systems/AssetManager.cpp index 1fa0387..ccbcbd7 100644 --- a/src/core/systems/AssetManager.cpp +++ b/src/core/systems/AssetManager.cpp @@ -18,6 +18,7 @@ namespace OX // Map from actual file path to virtual ID std::unordered_map AssetManager::s_PathToID; std::mutex AssetManager::s_AssetMutex; + std::mutex AssetManager::s_TreeMutex; std::shared_ptr AssetManager::s_FileTree = std::make_shared(); @@ -96,7 +97,7 @@ namespace OX { std::lock_guard lock(s_AssetMutex); // now fill in the real metadata - s_MetadataMap[resPath] = { type, path.string() }; + s_MetadataMap[resPath] = {type, path.string()}; } std::lock_guard qlock(s_QueueMutex); s_TextureQueue.push({resPath, w, h, ch, data}); @@ -138,7 +139,6 @@ namespace OX // Also map original file path to this ID auto meta = s_MetadataMap[pending.id]; s_PathToID[meta.absolutePath] = pending.id; - } } @@ -224,6 +224,7 @@ namespace OX pos = next + 1; } if (pos < resPath.size()) parts.push_back(resPath.substr(pos)); + std::lock_guard lock(AssetManager::s_TreeMutex); auto current = s_FileTree; for (size_t i = 1; i < parts.size(); ++i) { diff --git a/src/core/systems/AssetManager.h b/src/core/systems/AssetManager.h index c9daae5..d0759b0 100644 --- a/src/core/systems/AssetManager.h +++ b/src/core/systems/AssetManager.h @@ -37,6 +37,9 @@ namespace OX { static std::shared_ptr GetFileTree(); static void SaveAssetPack(const std::string& outputPath); + static std::mutex s_TreeMutex; + + private: struct AssetMetadata { std::string type; @@ -69,6 +72,6 @@ namespace OX { // texture upload queue static std::queue s_TextureQueue; - static std::mutex s_QueueMutex; + static std::mutex s_QueueMutex; }; } diff --git a/src/editor/Windows/FileBrowser.cpp b/src/editor/Windows/FileBrowser.cpp index 6218871..38540a6 100644 --- a/src/editor/Windows/FileBrowser.cpp +++ b/src/editor/Windows/FileBrowser.cpp @@ -93,9 +93,17 @@ namespace OX ImGui::BeginChild("GridRegion", ImVec2(0, 0), false, ImGuiWindowFlags_AlwaysUseWindowPadding); ImGui::Columns(cols, nullptr, false); - for (auto &c: node->children) { - if (!_filter.empty() && !PassesFilter(c->name)) continue; + std::vector > children; + + { + std::lock_guard lock(AssetManager::s_TreeMutex); // assume you add this mutex + children = node->children; + } + for (auto& c : children) { if (!c) return; + + if (!_filter.empty() && !PassesFilter(c->name)) continue; + ImGui::PushID(c->path.c_str()); ImGui::BeginGroup();