SmashPhil / Vehicle-Framework

Core mod for Vehicles
Other
55 stars 30 forks source link

[Compatibility] More Faction Interaction (Continued) #115

Open Anrock opened 1 year ago

Anrock commented 1 year ago

Describe the bug Mod: More Faction Interaction (Continued) Mod github: https://github.com/emipa606/MoreFactionInteraction

"Help harvest" option in another faction settlement produces NPE

To Reproduce Steps to reproduce the behavior:

  1. Wait until some settlement asks for help with their harvest
  2. Create a vehicle caravan with two (probably only driver will work too) colonists in Mule truck (probably any vehicle will do) and sent them to the settlement
  3. Wait until caravan arrives
  4. Press "Help harvest"
  5. Press confirm in confirmation window

Additional context Upon pressing confirm there is an error in devlog

Exception filling window for Verse.Dialog_MessageBox: System.NullReferenceException: Object reference not set to an instance of an object
  at MoreFactionInteraction.World_Incidents.WorldObjectComp_SettlementBumperCropComp.NotifyCaravanArrived (RimWorld.Planet.Caravan caravan) [0x00023] in <29bcd04e6a6a4ce6a37c0d46aa6d6dfd>:0 
  at MoreFactionInteraction.World_Incidents.WorldObjectComp_SettlementBumperCropComp+<>c__DisplayClass12_0.<GetCaravanGizmos>b__1 () [0x00000] in <29bcd04e6a6a4ce6a37c0d46aa6d6dfd>:0 
  at Verse.Dialog_MessageBox.DoWindowContents (UnityEngine.Rect inRect) [0x00225] in <d006c28bc811417ea565feda544f6d2b>:0 
  at Verse.Window.InnerWindowOnGUI (System.Int32 x) [0x001d3] in <d006c28bc811417ea565feda544f6d2b>:0 
UnityEngine.StackTraceUtility:ExtractStackTrace ()
(wrapper dynamic-method) Verse.Log:Verse.Log.Error_Patch2 (string)
Verse.Window:InnerWindowOnGUI (int)
UnityEngine.GUI:CallWindowDelegate [(UnityEngine.GUI/WindowFunction,int,int,UnityEngine.GUISkin,int,single,single,UnityEngine.GUIStyle)](steam://openurl_external/https://steamcommunity.com/linkfilter/?url=http://(UnityEngine.GUI/WindowFunction,int,int,UnityEngine.GUISkin,int,single,single,UnityEngine.GUIStyle))

Looks like caravan is null in https://github.com/emipa606/MoreFactionInteraction/blob/main/Source/MoreFactionInteraction/World%20Incidents/WorldObjectComp_SettlementBumperCropComp.cs#L88

I saw mentionins that this mod had to recreate caravan stuff from ground up for vehicles so I assumed this can be fixed better on the Vehicle Framework part (and also because MFI isn't actively deloped too) but I also reported this issue to MFI.

I can provide a save game for repro but it's mod heavy.

XenoTheStrange commented 8 months ago

I just had this same issue (I think so anyway, by looking at the error message). I can't help with a harvest if my caravan is a vehicle caravan. I had to set up a temporary camp 2 tiles away and make an on-foot caravan to do the thing.

Also, I've found that setting up an encampment (like a vanilla mining camp) if you're part of a vehicle caravan is a good way to delete whatever pawns were in it and crash the game. Vehicles can be very finnicky. Even with these two actual bugs the most annoying part is still when I try to form a big caravan and have to redo the entire process because I didn't have my garage door open so the vehicles couldn't leave... or one time when everyone gathered the caravan at the border and just refused to exit with some redundant pathing error that I couldn't figure out.

abel1502 commented 7 months ago

Judging from the IL offset (0x23), it seems that the issue is actually vehicle caravans not having a WorldObjectComp_CaravanComp attached. Thus the result of caravan.GetComponent<WorldObjectComp_CaravanComp>() is null, and setting attributes on it is what causes the NullReferenceException.

This should be fixable with an XML patch -- essentially the same as this one in the original mod, but for defName="VehicleCaravan"