Bluedog-Design-Bureau icon indicating copy to clipboard operation
Bluedog-Design-Bureau copied to clipboard

ModuleSpaceDustTelescope has issues with 3 parts

Open Gordon-Dry opened this issue 3 years ago • 2 comments

https://github.com/post-kerbin-mining-corporation/SpaceDust

[LOG 00:06:36.422] PartLoader: Compiling Part 'Bluedog_DB/Parts/ProbeExpansion/OAO/bluedog_OAO3_PEP_instrument/bluedog_OAO3_PEP_instrument'
[WRN 00:06:36.429] PartLoader Warning: Variable techtag not found in Part
[ERR 00:06:36.440] Module ModuleSpaceDustTelescope threw during OnLoad: System.NullReferenceException: Object reference not set to an instance of an object
  at SpaceDust.InstrumentSlot..ctor (ConfigNode node) [0x0004d] in <b70eada172354af49f9646082edb0f34>:0 
  at SpaceDust.ModuleSpaceDustTelescope.OnLoad (ConfigNode node) [0x00034] in <b70eada172354af49f9646082edb0f34>:0 
  at PartModule.Load (ConfigNode node) [0x001ab] in <cd473063d3a2482f8d93d388d0c95035>:0 
[LOG 00:06:37.074] PartLoader: Compiling Part 'Bluedog_DB/Parts/ProbeExpansion/OAO/bluedog_OAO_SAO_instrument/bluedog_OAO_SAO_instrument'
[WRN 00:06:37.082] PartLoader Warning: Variable techtag not found in Part
[ERR 00:06:37.084] Module ModuleSpaceDustTelescope threw during OnLoad: System.NullReferenceException: Object reference not set to an instance of an object
  at SpaceDust.InstrumentSlot..ctor (ConfigNode node) [0x0004d] in <b70eada172354af49f9646082edb0f34>:0 
  at SpaceDust.ModuleSpaceDustTelescope.OnLoad (ConfigNode node) [0x00034] in <b70eada172354af49f9646082edb0f34>:0 
  at PartModule.Load (ConfigNode node) [0x001ab] in <cd473063d3a2482f8d93d388d0c95035>:0 
[LOG 00:06:37.541] PartLoader: Compiling Part 'Bluedog_DB/Parts/ProbeExpansion/OAO/bluedog_OAO_WEP_instrument/bluedog_OAO_WEP_instrument'
[WRN 00:06:37.550] PartLoader Warning: Variable techtag not found in Part
[ERR 00:06:37.552] Module ModuleSpaceDustTelescope threw during OnLoad: System.NullReferenceException: Object reference not set to an instance of an object
  at SpaceDust.InstrumentSlot..ctor (ConfigNode node) [0x0004d] in <b70eada172354af49f9646082edb0f34>:0 
  at SpaceDust.ModuleSpaceDustTelescope.OnLoad (ConfigNode node) [0x00034] in <b70eada172354af49f9646082edb0f34>:0 
  at PartModule.Load (ConfigNode node) [0x001ab] in <cd473063d3a2482f8d93d388d0c95035>:0 

Gordon-Dry avatar Nov 05 '21 00:11 Gordon-Dry

I guess the issue is that the Bluedog_DB patch does only add a ModuleSpaceDustTelescope while SpaceDust itself also adds ModuleB9PartSwitch for instrument slots.

Perhaps an outdated method?

Gordon-Dry avatar Dec 16 '21 18:12 Gordon-Dry

From reading SpaceDust's C# code and looking at the relevant cfg files, it looks to me like the reason it's happening with BDB's ModuleSpaceDustTelescopes and not with SpaceDust's is because when BDB sets each ModuleSpaceDustTelescope's SLOT's Instrument to something other than None, that causes SpaceDust to try to look up the instruments in SpaceDustInstruments.Instance. The exception is because SpaceDustInstruments.Instance is null when KSP is still loading stuff (and also when it has only reached the main menu). (SpaceDustInstruments is tagged with a [KSPAddon(KSPAddon.Startup.AllGameScenes, false)] annotation, and Instance is assigned in OnLoad.)

SpaceDust making it so the Instruments can only be switched from None using B9PartSwitch would seem to ensure that it doesn't try to look up the instruments prematurely.

Fortunately, SpaceDust tries again upon reaching a game scene, so despite the exceptions the instruments do eventually get initialized, and do work.

AmanitaVerna avatar Jul 03 '22 13:07 AmanitaVerna