Skip to content

Commit c2c5d3f

Browse files
Copilotsheazywi
andauthored
Address code review: fix busy-wait, add file-open error handling
Agent-Logs-Url: https://github.com/starbounded-dev/LuxEngine/sessions/a7b976e8-d569-4fb6-889e-44131bcfcc6a Co-authored-by: sheazywi <73042839+sheazywi@users.noreply.github.com>
1 parent b041bdf commit c2c5d3f

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

Core/Source/Lux/Asset/MaterialSerializer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ namespace Lux
4242
out << YAML::EndMap;
4343

4444
std::ofstream fout(filepath);
45+
if (!fout.is_open())
46+
{
47+
LUX_CORE_ERROR("MaterialSerializer: Could not open '{}' for writing", filepath.string());
48+
return;
49+
}
4550
fout << out.c_str();
4651
}
4752

Core/Source/Lux/Asset/MeshSerializer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ namespace Lux
5656
out << YAML::EndMap;
5757

5858
std::ofstream fout(filepath);
59+
if (!fout.is_open())
60+
{
61+
LUX_CORE_ERROR("MeshSerializer: Could not open '{}' for writing", filepath.string());
62+
return;
63+
}
5964
fout << out.c_str();
6065
}
6166

@@ -119,6 +124,11 @@ namespace Lux
119124
out << YAML::EndMap;
120125

121126
std::ofstream fout(filepath);
127+
if (!fout.is_open())
128+
{
129+
LUX_CORE_ERROR("StaticMeshSerializer: Could not open '{}' for writing", filepath.string());
130+
return;
131+
}
122132
fout << out.c_str();
123133
}
124134

Core/Source/Lux/Asset/RuntimeAssetManager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace Lux {
2323
// runtime because assets are expected to be pre-loaded asynchronously.
2424
LUX_CORE_WARN("RuntimeAssetManager::GetAsset – synchronous load for handle {}", (uint64_t)handle);
2525

26-
// Trigger an async load and wait for it (simple spin).
26+
// Trigger an async load and sleep briefly between sync polls to avoid
27+
// burning CPU cycles while waiting for the worker thread.
2728
std::atomic_bool done{ false };
2829
LoadAssetAsync(handle, [&done](AssetHandle, Ref<Asset>)
2930
{
@@ -33,7 +34,8 @@ namespace Lux {
3334
while (!done)
3435
{
3536
SyncLoadedAssets();
36-
std::this_thread::yield();
37+
using namespace std::chrono_literals;
38+
std::this_thread::sleep_for(1ms);
3739
}
3840

3941
return IsAssetLoaded(handle) ? m_LoadedAssets.at(handle) : nullptr;

0 commit comments

Comments
 (0)