Vanilla-Expanded / VanillaExpandedFramework

Vanilla Expanded Framework for RimWorld
Other
73 stars 37 forks source link

NRE in Pawn_DrawTracker_Patch.Postfix #113

Open bonesbro opened 1 week ago

bonesbro commented 1 week ago

Crash looks like it's related to 21305e @RedMattis

The IL offset is 0x0066 which, decompiled, is this code:

// __result.z += threadStaticCache.cache.renderPosOffset;
IL_0065: nop
IL_0066: ldarg.0
IL_0067: ldflda float32 [UnityEngine.CoreModule]UnityEngine.Vector3::z
IL_006c: dup

My IL is pretty rusty, but I think that ldarg.0 followed by the reference to the vector z indicates that the NRE is because __result is null.

Haven't done much investigation to find a less specific repro case, but in this case it was casting a particular spell (Summon Spirit Wolves) from the Rimworld of Magic mod. Whatever, super niche, but I hope the details are enough to help.

Slightly truncated call stack: Exception ticking Rhino (at (128, 0, 176)): System.NullReferenceException: Object reference not set to an instance of an object [Ref 5885F667] at VFECore.Pawn_DrawTracker_Patch.Postfix (UnityEngine.Vector3& __result, Verse.Pawn ___pawn) [0x00066] in <1b1b05ff0320402bacdfe2a192f60d1f>:0 at Verse.Pawn_DrawTracker.get_DrawPos () [0x00066] in <2a40c3593b334f29ac3cb3d32d652351>:0

erdelf commented 1 week ago

__result can't be null actually.

Full log please for clarity. Also gonna take a wild guess and say those Wolves don't have needs ?

TorannD commented 1 week ago

They do have needs, but I don't think that's the issue. Here's the full logs: https://gist.github.com/HugsLibRecordKeeper/1560e83c925650e25940d2692a42a780

The error is being generated by a call to pawn.DrawPos immediately after the pawn is spawned and done so to create a mote. FleckMaker.ThrowSmoke(animal.DrawPos, map, Rand.Range(.5f, 1.1f));

Removing VFE and adding in logs to check for null values....

Log.Message("animal.DrawPos: " + animal.DrawPos);
Log.Message("map: " + map);
FleckMaker.ThrowSmoke(animal.DrawPos, map, Rand.Range(.5f, 1.1f));

Output from the log messages doesn't show any null values: https://gist.github.com/HugsLibRecordKeeper/509c65893c754d13f0eb38d6ea17d3c3

animal.DrawPos: (89.5, 8.1, 121.5) map: Map-0-PlayerHome

I've switched the position to use animal.Position.ToVector3Shifted() which doesn't generate any errors with VFE.

Hope this helps identify the issue.