Skip to content

Commit 7ed614c

Browse files
committed
fix data race hazard, await running async before running a new one
1 parent 872d71d commit 7ed614c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

12_MeshLoaders/main.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,23 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
319319
if (geometries.empty())
320320
return false;
321321

322-
// TODO: do it async
323322
if (m_saveGeom)
323+
{
324+
if (m_saveGeomTaskFuture.valid())
325+
{
326+
m_logger->log("Waiting for previous geometry saving task to complete...", ILogger::ELL_INFO);
327+
m_saveGeomTaskFuture.wait();
328+
}
329+
330+
std::string currentGeomSavePath = m_specifiedGeomSavePath.value_or((m_saveGeomPrefixPath / path(m_modelPath).filename()).generic_string());
324331
m_saveGeomTaskFuture = std::async(
325332
std::launch::async,
326-
[this, geometries] { writeGeometry(
333+
[this, geometries, currentGeomSavePath] { writeGeometry(
327334
geometries[0],
328-
m_specifiedGeomSavePath.value_or((m_saveGeomPrefixPath / path(m_modelPath).filename()).generic_string())
335+
currentGeomSavePath
329336
); }
330337
);
338+
}
331339

332340
using aabb_t = hlsl::shapes::AABB<3,double>;
333341
auto printAABB = [&](const aabb_t& aabb, const char* extraMsg="")->void

0 commit comments

Comments
 (0)