Fix crash in animations system when assets gets loading/unloaded while async jobs are active
#2974
This commit is contained in:
@@ -27,6 +27,7 @@ class AnimationsSystem : public TaskGraphSystem
|
||||
{
|
||||
public:
|
||||
float DeltaTime, UnscaledDeltaTime, Time, UnscaledTime;
|
||||
bool Active;
|
||||
|
||||
void Job(int32 index);
|
||||
void Execute(TaskGraph* graph) override;
|
||||
@@ -51,6 +52,7 @@ namespace
|
||||
|
||||
AnimationsService AnimationManagerInstance;
|
||||
TaskGraphSystem* Animations::System = nullptr;
|
||||
ConcurrentSystemLocker Animations::SystemLocker;
|
||||
#if USE_EDITOR
|
||||
Delegate<Animations::DebugFlowInfo> Animations::DebugFlow;
|
||||
#endif
|
||||
@@ -116,6 +118,10 @@ void AnimationsSystem::Execute(TaskGraph* graph)
|
||||
{
|
||||
if (AnimationManagerInstance.UpdateList.Count() == 0)
|
||||
return;
|
||||
Active = true;
|
||||
|
||||
// Ensure no animation assets it being reloading/modified before running async update
|
||||
Animations::SystemLocker.Begin(false);
|
||||
|
||||
// Setup data for async update
|
||||
const auto& tickData = Time::Update;
|
||||
@@ -138,6 +144,8 @@ void AnimationsSystem::Execute(TaskGraph* graph)
|
||||
|
||||
void AnimationsSystem::PostExecute(TaskGraph* graph)
|
||||
{
|
||||
if (!Active)
|
||||
return;
|
||||
PROFILE_CPU_NAMED("Animations.PostExecute");
|
||||
|
||||
// Update gameplay
|
||||
@@ -153,6 +161,8 @@ void AnimationsSystem::PostExecute(TaskGraph* graph)
|
||||
|
||||
// Cleanup
|
||||
AnimationManagerInstance.UpdateList.Clear();
|
||||
Animations::SystemLocker.End(false);
|
||||
Active = false;
|
||||
}
|
||||
|
||||
void Animations::AddToUpdate(AnimatedModel* obj)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "Engine/Scripting/ScriptingType.h"
|
||||
#include "Engine/Core/Delegate.h"
|
||||
#include "Engine/Threading/ConcurrentSystemLocker.h"
|
||||
|
||||
class TaskGraphSystem;
|
||||
class AnimatedModel;
|
||||
@@ -21,6 +22,9 @@ API_CLASS(Static) class FLAXENGINE_API Animations
|
||||
/// </summary>
|
||||
API_FIELD(ReadOnly) static TaskGraphSystem* System;
|
||||
|
||||
// Data access locker for animations data.
|
||||
static ConcurrentSystemLocker SystemLocker;
|
||||
|
||||
#if USE_EDITOR
|
||||
// Data wrapper for the debug flow information.
|
||||
API_STRUCT(NoDefault) struct DebugFlowInfo
|
||||
|
||||
Reference in New Issue
Block a user