Open V10lator opened 1 year ago
Forget to say: It doesn't always produce a crashlog. Also sometimes the game just freezes, sometimes this pops up: And sometimes this: (sorry about the bad quality shot)
Tried to rewrite Patches.cs
to this:
using Game.Prefabs;
using HarmonyLib;
using System.Runtime.InteropServices;
using Unity.Entities;
namespace BetterPedestrianPathfind;
[HarmonyPatch]
class Patches
{
[HarmonyPatch(typeof(PedestrianPathfind), "Initialize")]
[HarmonyPrefix]
static bool Prefix(ref EntityManager entityManager, ref Entity entity, PedestrianPathfind __instance) {
Logger.LogInfo("Override PedestrianPathfind called");
PathfindPedestrianData componentData = default(PathfindPedestrianData);
GCHandle gch = GCHandle.Alloc(componentData); // TODO: Unpin
componentData.m_WalkingCost = new PathfindCostInfo(0f, 0f, 0f, 0.01f).ToPathfindCosts();
componentData.m_CrosswalkCost = new PathfindCostInfo(0f, 0f, 0f, 5f).ToPathfindCosts();
componentData.m_UnsafeCrosswalkCost = new PathfindCostInfo(0f, 1000f, 0f, 5f).ToPathfindCosts();
componentData.m_SpawnCost = new PathfindCostInfo(5f, 0f, 0f, 0f).ToPathfindCosts();
entityManager.SetComponentData(entity, componentData);
// GCHandle.Free(gch); // TODO: Too early?
return false;
}
}
Can't test through as I don't know where to get the missing assembly Visual Studio complains about. So if you could compile this (maybe two times: One time like it is here and one time with the commented out line uncommented) and handle the result(s) over to me I could do some testing. :)
Note that I'm not 100% sure it will compile through: I'm not that familiar with C# / .NET, esp. not with its garbage collector.
Managed to compile and saw the real issue when comparing with game codes. Confirmed the fix with my bug triggering savegame and opened a PR. :)
I have a savegame here which crashes after around a minute after loading with the mod enabled. No crash w/o the mod.
Crashlog:
Complete LogOutput.txt (with Unity Log redirection enabled in BepInEx) :