diff --git a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll index f698e1be..eed6d611 100644 Binary files a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll and b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll differ diff --git a/Source/Restock/ModuleRestockHeatEffects.cs b/Source/Restock/ModuleRestockHeatEffects.cs index 94c23b3e..8700ed49 100644 --- a/Source/Restock/ModuleRestockHeatEffects.cs +++ b/Source/Restock/ModuleRestockHeatEffects.cs @@ -43,6 +43,7 @@ namespace Restock [KSPField] public bool disableBlackbody = false; public List renderers = new List(); + public List excludedRendererNames = new List(); private readonly string _shaderBlackbody = "_TemperatureColor"; @@ -103,22 +104,12 @@ namespace Restock { if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) return; - renderers = base.part.FindModelComponents(); - if (node.HasValue("excludedRenderer")) { - var excludedRenderers = new List(); - - excludedRenderers.AddRange(node.GetValues("excludedRenderer")); - - for (int i = renderers.Count - 1; i >= 0; i--) - { - if (renderers[i] == null || excludedRenderers.Contains(renderers[i].name)) - { - renderers.RemoveAt(i); - } - } + excludedRendererNames = new List(node.GetValues("excludedRenderer")); } + + FindRenderers(); } public void LateUpdate() @@ -140,7 +131,7 @@ namespace Restock temp = useSkinTemp ? base.part.skinTemperature : base.part.temperature; } - var temp2 = (float) ((temp - draperPoint) / _lerpRange); + var temp2 = (float)((temp - draperPoint) / _lerpRange); temp2 = Mathf.Clamp01(temp2); _emissiveColor.r = redCurve.Evaluate(temp2); @@ -156,9 +147,35 @@ namespace Restock _propertyBlock.SetColor(_shaderBlackbodyID, Color.black); } + try + { + UpdateRenderers(_propertyBlock); + } catch(NullReferenceException) + { + // if any renderers are null, rebuild renderer list + // any bonus renderers will just have to be ignored I guess + FindRenderers(); + UpdateRenderers(_propertyBlock); + } + } + + private void UpdateRenderers(MaterialPropertyBlock mpb) + { for (var i = 0; i < renderers.Count; i++) { - renderers[i].SetPropertyBlock(_propertyBlock); + renderers[i].SetPropertyBlock(mpb); + } + } + + private void FindRenderers() + { + renderers= part.FindModelComponents(); + + renderers.RemoveAll(renderer => renderer == null); + + if( excludedRendererNames.Count != 0) + { + renderers.RemoveAll(renderer => excludedRendererNames.Contains(renderer.name)); } } }