Fixed Crash By Adding Lock
This commit is contained in:
parent
1a928159e5
commit
375af6829c
@ -18,6 +18,7 @@ namespace OX
|
||||
// Map from actual file path to virtual ID
|
||||
std::unordered_map<std::string, std::string> AssetManager::s_PathToID;
|
||||
std::mutex AssetManager::s_AssetMutex;
|
||||
std::mutex AssetManager::s_TreeMutex;
|
||||
|
||||
std::shared_ptr<ResourceTreeNode> AssetManager::s_FileTree = std::make_shared<ResourceTreeNode>();
|
||||
|
||||
@ -96,7 +97,7 @@ namespace OX
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_AssetMutex);
|
||||
// now fill in the real metadata
|
||||
s_MetadataMap[resPath] = { type, path.string() };
|
||||
s_MetadataMap[resPath] = {type, path.string()};
|
||||
}
|
||||
std::lock_guard<std::mutex> 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<std::mutex> lock(AssetManager::s_TreeMutex);
|
||||
|
||||
auto current = s_FileTree;
|
||||
for (size_t i = 1; i < parts.size(); ++i) {
|
||||
|
@ -37,6 +37,9 @@ namespace OX {
|
||||
static std::shared_ptr<ResourceTreeNode> 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<PendingTexture> s_TextureQueue;
|
||||
static std::mutex s_QueueMutex;
|
||||
static std::mutex s_QueueMutex;
|
||||
};
|
||||
}
|
||||
|
@ -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<std::shared_ptr<ResourceTreeNode> > children;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> 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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user