Fix crash in particles system when assets gets loading/unloaded while async jobs are active

This commit is contained in:
Wojtek Figat
2025-02-18 23:27:49 +01:00
parent 060bc0aaf8
commit 937d369856
5 changed files with 26 additions and 3 deletions

View File

@@ -111,6 +111,7 @@ namespace ParticleManagerImpl
using namespace ParticleManagerImpl;
TaskGraphSystem* Particles::System = nullptr;
ConcurrentSystemLocker Particles::SystemLocker;
bool Particles::EnableParticleBufferPooling = true;
float Particles::ParticleBufferRecycleTimeout = 10.0f;
@@ -139,6 +140,8 @@ class ParticlesSystem : public TaskGraphSystem
{
public:
float DeltaTime, UnscaledDeltaTime, Time, UnscaledTime;
bool Active;
void Job(int32 index);
void Execute(TaskGraph* graph) override;
void PostExecute(TaskGraph* graph) override;
@@ -1390,6 +1393,10 @@ void ParticlesSystem::Execute(TaskGraph* graph)
{
if (UpdateList.Count() == 0)
return;
Active = true;
// Ensure no particle assets can be reloaded/modified during async update
Particles::SystemLocker.Begin(false);
// Setup data for async update
const auto& tickData = Time::Update;
@@ -1406,8 +1413,13 @@ void ParticlesSystem::Execute(TaskGraph* graph)
void ParticlesSystem::PostExecute(TaskGraph* graph)
{
if (!Active)
return;
PROFILE_CPU_NAMED("Particles.PostExecute");
// Cleanup
Particles::SystemLocker.End(false);
Active = false;
UpdateList.Clear();
#if COMPILE_WITH_GPU_PARTICLES