TweakScale/Companion_KIAS

NRE when TweakScale dispatches OnRescale after upgrading a Scale Type that was changed on some patch

Lisias opened this issue · 3 comments

AS the tittle says.

Reported by Alexsys.

Evidences: KSP-log-MM-configcache.zip

[LOG 10:11:42.686] [TweakScale] WARNING: Upgrading ScaleType! Craft 4294221486 had the part KIS.Container7:FFF574EC scaling changed from (TweakScale: default=3.750, current=5.000) to (stack: default=3.750, current=5.000)
[LOG 10:11:42.694] [TweakScale] ERROR: Exception on rescale while ¬TSGenericUpdater: System.NullReferenceException: Object reference not set to an instance of an object
  at TweakScaleCompanion.KIS.Inventory.TweakScalerKISInventory.OnRescale (TweakScale.ScalingFactor factor) [0x0004a] in <42b57c759f324dc5a585d250c585fb00>:0
  at TweakScaleCompanion.KIS.Inventory.Scaler.OnRescale (TweakScale.ScalingFactor factor) [0x00000] in <42b57c759f324dc5a585d250c585fb00>:0
  at TweakScale.TweakScale.CallUpdaters () [0x000bb] in <028f737b7f48427b8228acc501dc7867>:0  at error:0
[LOG 10:11:42.698] [TweakScale] WARNING: Upgrading ScaleType! Craft 4294002924 had the part ServiceBay.250.v2:FFF56500 scaling changed from (TweakScale: default=2.500, current=5.000) to (stack: default=2.500, current=5.000)

Note that only Parts with KIS are borking (obviously).

That's what happened:

When TweakScale detects that the scale part of a living part had changed, it try to salvage the part by applying the new scaletype respecting the proportions from the older one. The part didn't changed sizes, it changed size definitions, and so TweakScale rework the part in order to keep the same current size with the new definitions.

When this happens, TweakScale needs to advise all eventual custom scalers about the change, because TweakScale doesn't have how to know if some of them were already Started (and, so, they need to redo the scaling with the new definitions), of if they didn't started yet (and so this would not be a problem, because they would start already with the right definitions).

Problem: as I said, TweakScale can't know if the custom scalers had already started or not, so it dispatches the OnRescale event anyway.

But that changed a bit the life cycle of the custom scalers - before the "TweakScale Upgrade Pipeline" stunt the OnRescale was never called before everybody had started already, and now they are. TSC-KIS was not handling this borderline situation, and so BADA-BOOM. :/

Well, problem diagnosed. Fixing it.

Fixed on commit: 4b20be7

Note: this issue is related to TweakScale/TweakScale#236