blowfishpro / B9PartSwitch

A Kerbal Space Program plugin designed to implement switching of part meshes, resources, and nodes
GNU Lesser General Public License v3.0
50 stars 33 forks source link

Removing PartModule at runtime causes index mismatching #87

Closed Starwaster closed 6 years ago

Starwaster commented 6 years ago

Removing modules (ModuleB9PartInfo for example) causes index mismatch errors if another module occupies the missing module's indexed location. (anything after the missing module is shifted upwards).

When it appears in the prefab but is missing in flight mode, KSP tries to compensate by relocating the loaded modules to another location but this can be disastrous if there was more than one module by that name (multiple generator modules for example. KSP sees that the loaded module occupies a spot that MB9PI occupied in the prefab so it looks for a slot with an identically named module and loads into the first eligible slot that it finds)

If there IS more than one module by that name then they end up getting the wrong data loaded in.

So as an alternative to removing modules outright, how about just disabling it? You can save someone maybe five days worth of troubleshooting.....

blowfishpro commented 6 years ago

Nothing ever removes ModuleB9PartInfo, it's just selective about what it gets added to. Was the problem that some part config changed which caused the module to be removed?

I could change it so that it adds ModuleB9PartInfo to every part with ModuleB9PartSwitch, this might help reduce conflicts when configs are changed.

And yes, the way KSP tries to map them is pretty horrible. I have code specifically in here to prevent bad data from being loaded into ModuleB9PartSwitch: https://github.com/blowfishpro/B9PartSwitch/blob/130354d72b9ba62e0af3fe66bdaa90e8f658f189/B9PartSwitch/CustomPartModule.cs#L55

Starwaster commented 6 years ago

No, the problem is that the module is being removed at runtime as seen below (when switching to flight mode)

https://github.com/blowfishpro/B9PartSwitch/blob/master/B9PartSwitch/PartSwitch/ModuleB9PartInfo.cs#L39-L46

blowfishpro commented 6 years ago

Oh, yeah I forgot about that. Sure, I can have it not do that.

Starwaster commented 6 years ago

Thanks