sarbian / ModuleManager

177 stars 95 forks source link

!EXPERIMENT_DEFINITION doesn't delete definition; duplicates cause KSP to throw exception #4

Open xEvilReeperx opened 10 years ago

xEvilReeperx commented 10 years ago

Affects: versions 1.5.6 and 2.0.3

A config like this:

!EXPERIMENT_DEFINITION[crewReport]
EXPERIMENT_DEFINITION
{
    id = crewReport
    title = Crew Report
    baseValue = 5
    scienceCap = 5
    dataScale = 1
    requireAtmosphere = False
    situationMask = 63
    biomeMask = 7
    RESULTS
    {
        default = You record the crew's assessment of the situation.
    }
}

Will cause two "crewReport" ConfigNodes to exist (verified by:)


foreach (var node in GameDatabase.Instance.GetConfigNodes("EXPERIMENT_DEFINITION"))
    Log.Write("Experiment_def: {0}", node.ToString());

Then, any time ResearchAndDevelopment.GetExperimentIDs() is called, KSP will throw the following exception:

ArgumentException: An element with the same key already exists in the dictionary.
  at System.Collections.Generic.Dictionary`2[System.String,ScienceExperiment].Add (System.String key, .ScienceExperiment value) [0x00000] in <filename unknown>:0 

  at ResearchAndDevelopment.loadExperiments () [0x00000] in <filename unknown>:0 

  at ResearchAndDevelopment.GetExperimentIDs () [0x00000] in <filename unknown>:0 

  at ScienceAlert.Settings..ctor () [0x00000] in <filename unknown>:0 

  at ScienceAlert.Settings.get_Instance () [0x00000] in <filename unknown>:0 

  at ScienceAlert.AudioController..ctor () [0x00000] in <filename unknown>:0 

  at ScienceAlert.EffectController..ctor (ScienceAlert.ScienceAlert indi) [0x00000] in <filename unknown>:0 

  at ScienceAlert.ScienceAlert.Start () [0x00000] in <filename unknown>:0 
sarbian commented 10 years ago

That's because deleting does not work (yet) for a root node. Someone as shown me some code to do that, I ll add it soonish. Edit : you could edit the content of the node instead of deleting and recreating it;

blowfishpro commented 7 years ago

I don't think this is still an issue. Can this be closed?