diff --git a/Source/Engine/Content/Assets/Animation.cpp b/Source/Engine/Content/Assets/Animation.cpp index 789153c21..8788f1466 100644 --- a/Source/Engine/Content/Assets/Animation.cpp +++ b/Source/Engine/Content/Assets/Animation.cpp @@ -502,6 +502,24 @@ void Animation::OnSkinnedModelUnloaded(Asset* obj) MappingCache.Remove(i); } +void Animation::OnScriptingDispose() +{ + // Dispose any events to prevent crashes (scripting is released before content) + for (auto& e : Events) + { + for (auto& k : e.Second.GetKeyframes()) + { + if (k.Value.Instance) + { + Delete(k.Value.Instance); + k.Value.Instance = nullptr; + } + } + } + + BinaryAsset::OnScriptingDispose(); +} + Asset::LoadResult Animation::load() { // Get stream with animations data diff --git a/Source/Engine/Content/Assets/Animation.h b/Source/Engine/Content/Assets/Animation.h index 8c9b9c095..80085e392 100644 --- a/Source/Engine/Content/Assets/Animation.h +++ b/Source/Engine/Content/Assets/Animation.h @@ -163,6 +163,11 @@ private: void OnSkinnedModelUnloaded(Asset* obj); +public: + + // [BinaryAsset] + void OnScriptingDispose() override; + protected: // [BinaryAsset]