Fix for sickbays erroneously consuming resources after rendezvous #884
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for a bug I found with sickbays where rendezvousing with a vessel that contains a part with a configurable sickbay would cause it to start consuming electricity and other resources as if all possible sickbay modules were running at the same time. To reproduce the bug, launch a vessel with a PPD-10 Hitchhiker crew container with nothing configured in the sickbay, and then launch a 2nd vessel and rendezvous with the first. When the vessel with the Hitchhiker container comes within physics range and loads into the scene, it will immediately start consuming electricity and oxygen for both the sickbay TV and RDU processes, despite originally being configured with neither sickbay modules. This bug is present in both Kerbalism versions 3.18 and 3.19.
Here are screenshots showing electricity consumption before and after rendezvousing for the target vessel that has a PPD-10 Hitchhiker part on it:
Before rendezvous:
After rendezvous:
As shown in the screenshots, the vessel has started consuming electricity and oxygen for the RDU and TV, despite being configured with neither when launched.
When debugging this, I discovered that loading a vessel normally by launching or focusing it from the tracking station would call
Sickbay.Start()
immediately followed bySickbay.Update()
, however when rendezvousing with the vessel, onlySickbay.Start()
would be called. If both Start and Update are called, the resultingamount
values for_SickbayTV
and_SickbayRDU
are set to 0, but if only Start is called, theamount
values would end up being set to 1. This is becauseSickbay.Start()
callsSickbay.Configure()
with the first parameter hardcoded totrue
, resulting inLib.SetResource()
to be called for the TV and RDU with anamount
value of 1. I am unsure if rendezvouses only callingSickbay.Start()
without callingSickbay.Update()
is a separate bug or not.This change now ensures that the
amount
value for_SickbayTV
and_SickbayRDU
will only be set to 1 if the sickbay module configured in the part, which will setisEnabled
totrue
. Otherwise, if the sickbay is not configured,isEnabled
for_SickbayTV
and_SickbayRDU
will befalse
, and theamount
value will always be 0.I have tested this change with various different sickbay configurations and have not found any erroneous behavior.