woolstrand / RealRuins

11 stars 11 forks source link

Exception when generating world #63

Open Vectorial1024 opened 1 year ago

Vectorial1024 commented 1 year ago

Describe the bug Something went wrong while generating the world (insert seeds, etc -> generate world -> error); most probably related to this mod.

To Reproduce Steps to reproduce the behavior:

  1. Go generate a new world
  2. Select the parameters, e.g. what Storyteller, etc
  3. Click generate
  4. Wait for generate
  5. Planet is generated, but the generate world parameters screen is also on.

Expected behavior Should just show the planet screen.

Error Logs

Could not execute post-long-event action. Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at RealRuins.RealRuins+Page_SelectStartingSite_PostOpen_Patch.Postfix () [0x00001] in <ecd4f075030b40bda18e91c93acf8507>:0 
  at (wrapper dynamic-method) RimWorld.Page_SelectStartingSite.RimWorld.Page_SelectStartingSite.PostOpen_Patch2(RimWorld.Page_SelectStartingSite)
  at (wrapper dynamic-method) Verse.WindowStack.Verse.WindowStack.Add_Patch1(Verse.WindowStack,Verse.Window)
  at RimWorld.Page_CreateWorldParams.<CanDoNext>b__19_1 () [0x0000d] in <95de19971c5d40878d8742747904cdcd>:0 
  at Verse.LongEventHandler.ExecuteToExecuteWhenFinished () [0x0007c] in <95de19971c5d40878d8742747904cdcd>:0 
UnityEngine.StackTraceUtility:ExtractStackTrace ()
(wrapper dynamic-method) Verse.Log:Verse.Log.Error_Patch3 (string)
Verse.LongEventHandler:ExecuteToExecuteWhenFinished ()
Verse.LongEventHandler:UpdateCurrentAsynchronousEvent ()
Verse.LongEventHandler:LongEventsUpdate (bool&)
(wrapper dynamic-method) Verse.Root:Verse.Root.Update_Patch1 (Verse.Root)
Verse.Root_Entry:Update ()
bowers12 commented 1 year ago

Hi, I just had this issue also. For me, it was because of the new Planetary Ruins feature, and the fact it has new settings associated with it. Deleting my old RealRuins config file (Mod_1552146295_RealRuins_Mod.xml in ...\AppData\LocalLow\Ludeon Studios\RimWorld by Ludeon Studios\Config in my case) and letting it regenerate seemed to fix the issue.

kathanon commented 4 months ago

This issue occurs because Scribe_Deep.Look has null as the default value if the node is not present. Thus for any user with an outdated config file, the field gets reset to null when loading the options.

The easiest way to solve it is to add something like this to the end of RealRuins_ModSettings.ExposeData:

if (Scribe.mode == LoadSaveMode.LoadingVars) {
    if (defaultScatterOptions == null) {
        defaultScatterOptions = new ScatterOptions();
    }
    if (planetaryRuinsOptions == null) {
        planetaryRuinsOptions = new PlanetaryRuinsOptions();
    }
}
Vectorial1024 commented 4 months ago

Depending on the exact C# version, we could potentially simplify further using the ??= operator; ref https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator