Skip to content

Commit

Permalink
Fix exceptions in Content Browser
Browse files Browse the repository at this point in the history
  • Loading branch information
ForserX committed Oct 28, 2024
1 parent 6a05497 commit 3ac2936
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
48 changes: 17 additions & 31 deletions src/Editors/LevelEditor/Editor/Utils/ContentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ void CContentView::Draw()
{
DrawHeader();

if (Files.empty() && !IsFindResult && !IsSpawnElement)
if ((NeedRescan || Files.empty()) && !IsFindResult && !IsSpawnElement)
{
RescanDirectory();
NeedRescan = false;
}

while (LockFiles)
continue;

LockFiles = true;

if (ImGui::BeginChild("##contentbrowserscroll"))
{
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_None) && ImGui::IsMouseReleased(1) && !ImGui::IsItemHovered())
Expand Down Expand Up @@ -78,7 +74,6 @@ void CContentView::Draw()
CurrentItemHint.Active = false;
}

LockFiles = false;
ImGui::EndChild();
}

Expand Down Expand Up @@ -259,7 +254,7 @@ void CContentView::FindFile()
IsDelWatcher = true;
xr_delete(WatcherPtr);

Files.clear();
ClearFileList();
for (const auto& file : xr_dir_recursive_iter { CurrentDir.data() })
{
if (file.is_directory())
Expand All @@ -277,7 +272,7 @@ void CContentView::FindFile()
}
else if (IsSpawnElement)
{
Files.clear();
ClearFileList();

auto TempPath = ScanConfigs("");
ScanConfigsRecursive(TempPath, ParseStr);
Expand All @@ -287,7 +282,7 @@ void CContentView::FindFile()
IsDelWatcher = true;
xr_delete(WatcherPtr);

Files.clear();
ClearFileList();
for (const xr_dir_entry& file : xr_dir_recursive_iter { CurrentDir.data() })
{
if (file.is_directory())
Expand Down Expand Up @@ -341,7 +336,7 @@ void CContentView::DrawISEDir(size_t& HorBtnIter, const size_t IterCount)
{
IsSpawnElement = false;
ISEPath = "";
Files.clear();
ClearFileList();
}
else
{
Expand Down Expand Up @@ -400,7 +395,7 @@ void CContentView::DrawRootDir(size_t& HorBtnIter, const size_t& IterCount, xr_s
{
NextDir = NextDir.erase(NextDir.length() - 1);
}
Files.clear();
ClearFileList();
}

ImGui::EndDisabled();
Expand All @@ -425,7 +420,7 @@ void CContentView::DrawRootDir(size_t& HorBtnIter, const size_t& IterCount, xr_s

void CContentView::RescanISEDirectory(const xr_string& StartPath)
{
Files.clear();
ClearFileList();

if (!StartPath.empty() && StartPath != ISEPath)
{
Expand Down Expand Up @@ -472,7 +467,7 @@ void CContentView::DrawOtherDir(size_t& HorBtnIter, const size_t IterCount, xr_s
{
NextDir = RootDir;
}
Files.clear();
ClearFileList();
}

for (FileOptData FilePath : Files)
Expand All @@ -486,7 +481,7 @@ void CContentView::DrawOtherDir(size_t& HorBtnIter, const size_t IterCount, xr_s
{
NextDir = NextDir.erase(NextDir.length() - 1);
}
Files.clear();
ClearFileList();
break;
}
}
Expand Down Expand Up @@ -529,12 +524,17 @@ void CContentView::DrawOtherDir(size_t& HorBtnIter, const size_t IterCount, xr_s
}
}

void CContentView::ClearFileList()
{
Files.clear();
}

void CContentView::RescanDirectory()
{
IsDelWatcher = true;
xr_delete(WatcherPtr);

Files.clear();
ClearFileList();
for (const auto& file : xr_dir_iter{ CurrentDir.data() })
{
if (std::filesystem::is_directory(file))
Expand All @@ -555,21 +555,7 @@ void CContentView::RescanDirectory()
CurrentDir.data(),
[this](const std::string&, const filewatch::Event)
{
while (LockFiles || IsSpawnElement)
{
if (IsDelWatcher)
{
IsDelWatcher = false;
LockFiles = false;
return;
}

continue;
}

LockFiles = true;
Files.clear();
LockFiles = false;
NeedRescan = true;
}
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Editors/LevelEditor/Editor/Utils/ContentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class CContentView:
void DrawRootDir(size_t& HorBtnIter, const size_t& IterCount, xr_string& NextDir);
void DrawOtherDir(size_t& HorBtnIter, const size_t IterCount, xr_string& NextDir);

void ClearFileList();

void RescanISEDirectory(const xr_string& path);
void RescanDirectory();

Expand Down Expand Up @@ -129,7 +131,7 @@ class CContentView:
xr_string ISEPath;
string32 FindStr = {};

volatile xr_atomic_bool LockFiles = false;
volatile xr_atomic_bool NeedRescan = false;

float TextHeight = 0.f;

Expand Down

0 comments on commit 3ac2936

Please sign in to comment.