fix memory leak related to anim clips

This commit is contained in:
in0finite 2019-07-14 15:29:00 +02:00
parent 6ffaf6a552
commit 8cae6c9206

View file

@ -217,6 +217,9 @@ namespace SanAndreasUnity.Behaviours
_anim = this.gameObject.GetOrAddComponent<UnityEngine.Animation> ();
// remove mixing transforms for all anim states
this.RemoveAllMixingTransformsForAllAnimStates();
LoadModel(Definition.ModelName, Definition.TextureDictionaryName);
// save original model state
@ -262,7 +265,6 @@ namespace SanAndreasUnity.Behaviours
Destroy(_frames.Root.gameObject);
Destroy(_frames);
_frames = null;
_loadedAnims.Clear();
}
var geoms = Geometry.Load(modelName, txds);
@ -491,8 +493,9 @@ namespace SanAndreasUnity.Behaviours
List<Transform> list;
if (m_mixedTransforms.TryGetValue (state, out list)) {
int count = list.Count;
foreach (var mix in list) {
state.RemoveMixingTransform (mix);
foreach (Transform mix in list) {
if (mix != null)
state.RemoveMixingTransform (mix);
}
list.Clear ();
return count;
@ -501,6 +504,17 @@ namespace SanAndreasUnity.Behaviours
}
}
public void RemoveAllMixingTransformsForAllAnimStates()
{
foreach (AnimationState s in this.AnimComponent)
{
if (s != null)
this.RemoveAllMixingTransforms(s);
}
m_mixedTransforms.Clear();
}
public Anim GetAnim (AnimGroup group, AnimIndex anim)
{