From d3073f52518f6d6dbd3c2e2616977904c320dd61 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 20 Jun 2023 21:47:05 +0300 Subject: [PATCH] Release custom assets before scripting hot reload --- Source/Engine/Scripting/Scripting.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Scripting/Scripting.cpp b/Source/Engine/Scripting/Scripting.cpp index 9bddc333e..bbd109cd1 100644 --- a/Source/Engine/Scripting/Scripting.cpp +++ b/Source/Engine/Scripting/Scripting.cpp @@ -640,9 +640,9 @@ void Scripting::Reload(bool canTriggerSceneReload) MCore::GC::WaitForPendingFinalizers(); // Destroy objects from game assemblies (eg. not released objects that might crash if persist in memory after reload) + const auto flaxModule = GetBinaryModuleFlaxEngine(); _objectsLocker.Lock(); { - const auto flaxModule = GetBinaryModuleFlaxEngine(); for (auto i = _objectsDictionary.Begin(); i.IsNotEnd(); ++i) { auto obj = i->Value; @@ -657,6 +657,15 @@ void Scripting::Reload(bool canTriggerSceneReload) } _objectsLocker.Unlock(); + // Release assets sourced from game assemblies + for (auto asset : Content::GetAssets()) + { + if (asset->GetTypeHandle().Module == flaxModule) + continue; + + asset->DeleteObjectNow(); + } + // Unload all game modules LOG(Info, "Unloading game binary modules"); auto modules = BinaryModule::GetModules();