crecheng / DSPMod

戴森球计划mod Dyson Sphere Project
Apache License 2.0
9 stars 4 forks source link

NRE in InitPowerUpdate() #6

Closed sp00ktober closed 2 years ago

sp00ktober commented 3 years ago

This error only happens when starting a new game.

[Error  : Unity Log] Thread Error Exception!!! Thread idx:11 LabOutput2Next Factory idx:0 LabOutput2Next gametick System.NullReferenceException: Object reference not set to an instance of an object
  at CommonAPI.ComponentTypePool.InitUpdate () [0x0001a] in <5f356e1a9f6e4e3a9c50a90806901285>:0
  at CommonAPI.Pool`1[T].UpdatePoolMultithread (System.Int32 usedThreadCount, System.Int32 currentThreadIdx, System.Int32 minimumCount, System.Func`1[TResult] initFunc) [0x00014] in <5f356e1a9f6e4e3a9c50a90806901285>:0
  at CommonAPI.ComponentSystem.UpdateMultithread (System.Int32 usedThreadCount, System.Int32 currentThreadIdx, System.Int32 minimumCount) [0x00013] in <5f356e1a9f6e4e3a9c50a90806901285>:0
  at CommonAPI.FactorySystemStorage.UpdateMultithread (PlanetFactory factory, System.Int32 usedThreadCount, System.Int32 currentThreadIdx, System.Int32 minimumCount) [0x00017] in <5f356e1a9f6e4e3a9c50a90806901285>:0
  at CommonAPI.CustomFactory.UpdateMultithread (PlanetFactory factory, System.Int32 usedThreadCount, System.Int32 currentThreadIdx, System.Int32 minimumCount) [0x00012] in <5f356e1a9f6e4e3a9c50a90806901285>:0
  at CommonAPI.FactorySystemPatch.UpdateMultithread (FactorySystem __instance, System.Int64 time, System.Boolean isActive, System.Int32 _usedThreadCnt, System.Int32 _curThreadIdx) [0x00001] in <5f356e1a9f6e4e3a9c50a90806901285>:0
  at FactorySystem.GameTickLabOutputToNext (System.Int64 time, System.Boolean isActive, System.Int32 _usedThreadCnt, System.Int32 _curThreadIdx, System.Int32 _minimumMissionCnt) [0x00005] in <b91ee4606c7b437f97b70b73197d6f25>:0
  at WorkerThreadExecutor.LabOutput2NextPartExecute () [0x00035] in <b91ee4606c7b437f97b70b73197d6f25>:0

(Error above related but the image below shows the issue) Mod is DSPSaveMod and afaik because IntoOtherSave is called too early

grafik

limoka commented 3 years ago

More details regarding this issue. Error above is only a symptom. Real issue is that function IntoOtherSave is being called too early for new games. When loading and saving its called on initialized game state. But when its called on new save its called before anything is even initialized. This inconsistency is what causes error above. Fix is simple though: change patch on function EnterGame from [HarmonyPatch(typeof(UIGalaxySelect), "EnterGame")] To [HarmonyPatch(typeof(GameData), "NewGame")] This will fix this issue.

limoka commented 2 years ago

Fixed by reuploading the mod under different name with the fix. https://dsp.thunderstore.io/package/CommonAPI/DSPModSave/