From 99d3da467e6dfc57e5ebc96606f839c5340abbe9 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 24 Mar 2026 17:45:06 +0100 Subject: [PATCH] Fix deadlock when hot-reloading scripts in Editor while `Animation` asset gets auto-saved #3942 --- Source/Engine/Content/Assets/Animation.cpp | 23 +++++++++++++++++----- Source/Engine/Content/Assets/Animation.h | 4 ++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Content/Assets/Animation.cpp b/Source/Engine/Content/Assets/Animation.cpp index 917db28ac..86fa41f89 100644 --- a/Source/Engine/Content/Assets/Animation.cpp +++ b/Source/Engine/Content/Assets/Animation.cpp @@ -691,11 +691,7 @@ Asset::LoadResult Animation::load() continue; } #if USE_EDITOR - if (!_registeredForScriptingReload) - { - _registeredForScriptingReload = true; - Level::ScriptsReloadStart.Bind(this); - } + _registerForScriptingReload = true; #endif } } @@ -733,6 +729,7 @@ void Animation::unload(bool isReloading) { ScopeWriteLock systemScope(Animations::SystemLocker); #if USE_EDITOR + _registerForScriptingReload = false; if (_registeredForScriptingReload) { _registeredForScriptingReload = false; @@ -752,6 +749,22 @@ void Animation::unload(bool isReloading) NestedAnims.Clear(); } +#if USE_EDITOR + +void Animation::onLoaded_MainThread() +{ + if (_registerForScriptingReload && !_registeredForScriptingReload) + { + _registeredForScriptingReload = true; + Level::ScriptsReloadStart.Bind(this); + } + _registerForScriptingReload = false; + + BinaryAsset::onLoaded_MainThread(); +} + +#endif + AssetChunksFlag Animation::getChunksToPreload() const { return GET_CHUNK_FLAG(0); diff --git a/Source/Engine/Content/Assets/Animation.h b/Source/Engine/Content/Assets/Animation.h index 4f4a773b4..c342cc64c 100644 --- a/Source/Engine/Content/Assets/Animation.h +++ b/Source/Engine/Content/Assets/Animation.h @@ -78,6 +78,7 @@ API_CLASS(NoSpawn) class FLAXENGINE_API Animation : public BinaryAsset private: #if USE_EDITOR + bool _registerForScriptingReload = false; bool _registeredForScriptingReload = false; void OnScriptsReloadStart(); #endif @@ -163,5 +164,8 @@ protected: // [BinaryAsset] LoadResult load() override; void unload(bool isReloading) override; +#if USE_EDITOR + void onLoaded_MainThread() override; +#endif AssetChunksFlag getChunksToPreload() const override; };