ApacheTech-VintageStory-Mods / ApacheTech.VintageMods.CampaignCartographer

Mod for Vintage Story: Adds multiple Cartography related features to the game, such as custom waypoint icons, GPS, auto waypoint markers, and more.
7 stars 4 forks source link

[BUG] Strange `NullReferenceException` bug with `PositionExtensions.RelativeToSpawn()`. #15

Closed ApacheTech closed 2 years ago

ApacheTech commented 2 years ago

Describe the Bug:

TL Crash
Running on 64 bit Windows with 16 GB RAM 
Game Version: v1.16.1 (Stable)
Loaded Mods: bettercrates@1.4.1, extrachests@1.5.1, midnight-texturepackNS@1.1.0, specializedbags-10Slot@0.4.1, tradeomat@1.6.0, game@1.16.1, zoombuttonreborn@1.2.0, carrycapacity@0.6.4, farmlanddropssoil@1.4.0, hudclock@2.7.0, medievalexpansion@3.7.1, prospectorinfo@3.1.2, creative@1.16.1, survival@1.16.1, workbenchexpansion@1.4.1, campaigncartographer@2.0.2, bricklayers@0.8.1
2022-02-01 22:10:48: Critical error occurred
System.NullReferenceException: Objektreferensen har inte angetts till en instans av ett objekt.
   vid ApacheTech.VintageMods.Core.Extensions.Game.PositionExtensions.RelativeToSpawn(BlockPos pos)
   vid ApacheTech.VintageMods.CampaignCartographer.Features.ManualWaypoints.Extensions.BlockEntityStaticTranslocatorExtensions.AddWaypoint(BlockPos sourcePos, BlockPos destPos, String titleTemplate)
   vid ApacheTech.VintageMods.CampaignCartographer.Features.ManualWaypoints.Extensions.BlockEntityStaticTranslocatorExtensions.AddWaypointsForEndpoints(BlockEntityStaticTranslocator translocator, String titleTemplate)
   vid ApacheTech.VintageMods.CampaignCartographer.Features.ManualWaypoints.TranslocatorWaypoints.DefaultHandler(Int32 groupId, CmdArgs args)
   vid Vintagestory.Client.NoObf.ClientEventManager.TriggerNewModChatLine(Int32 groupid, String message, EnumChatType chattype, String data)
   vid Vintagestory.Client.NoObf.ClientCoreAPI.TriggerChatMessage(String message)
   vid Vintagestory.Client.NoObf.ClientMain.ExecuteMainThreadTasks(Single deltaTime)
   vid _vRo5OUTQG1GrM9nJI04WT53NTfD._up6Bx1j7zVizDBWAE3yF6nNCGNeA(Single )
   vid _aMv7wPQlA8cgDnAEfSbEgoGdVfy._5b9xtkxs5cZMXJBpJdsFujTxqHg(Single )
   vid _aMv7wPQlA8cgDnAEfSbEgoGdVfy._CZCOZeGO1GrDP5k5hCtFGOFJtVO(Single )
   vid Vintagestory.Client.NoObf.ClientPlatformWindows.window_RenderFrame(Object sender, FrameEventArgs e)
   vid System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   vid OpenTK.GameWindow.RaiseRenderFrame(Double elapsed, Double& timestamp) i C:\Users\Nexrem\Desktop\transfer\opentk\src\OpenTK\GameWindow.cs:rad 476
   vid OpenTK.GameWindow.DispatchRenderFrame() i C:\Users\Nexrem\Desktop\transfer\opentk\src\OpenTK\GameWindow.cs:rad 452
   vid OpenTK.GameWindow.Run(Double updates_per_second, Double frames_per_second) i C:\Users\Nexrem\Desktop\transfer\opentk\src\OpenTK\GameWindow.cs:rad 375
   vid _WBb7CwUzEOAcHICLKAiVW6NVIeN._6uyy3n9Ds2iEHGU5xys7eJtJVNh(_Bv3M5I4kdGBjvWkB5zNcVsHESud , String[] )
   vid _rip5UQmdVBLCq6ZoAXXnaN9jQJc._6uyy3n9Ds2iEHGU5xys7eJtJVNh(ThreadStart )
-------------------------------

To Reproduce: Steps to reproduce the behaviour:

  1. Fix a TL
  2. Wait for space time warp.
  3. Step on TL

Expected Behaviour: The game shouldn't crash to desktop, and two waypoints should be added to the map.

Additional Context

Apache — Today at 21:26
Has this happened more than once?

FrostMannen — Today at 21:27
First time. I had just fixed a TL, and stepped on it after it had warped the space/time continuum. Now I can't get online anymore. So will wait till the Storm is over, disable Cartographer and try to get online again

Apache — Today at 21:28
This shouldn't affect your ability to log on at all. 

FrostMannen — Today at 21:28
Strange 😮 I tried 2 times. Will try again now
Ok, without Cartographer it works

Apache — Today at 21:32
Could you clear your logs, and then try with the mod enabled? If it fails, can you send me your client-main.txt, and client-debug.txt files?
My mod doesn't save any information about waypoints, so I can't see what would make it crash like that.

FrostMannen — Today at 21:34
Ok, logging out and try again

FrostMannen — Today at 21:49
Now it works, but it also already made the "automatic" WP for the TL,
ApacheTech commented 2 years ago

Developer Notes:

So far as I can see, this can be attributed to the same bug in ApiEx.Side, where ThreadPool threads are cached, and then recycled. This should be an edge-case bug, because this method has been used for years with no issues. If problems persist, I'll need to revert to the original design for the RelativeToSpawn() method, where the API is passed as a parameter.

So far, this method has only ever been used on the Client, so it would be safe to ensure it's only used there by using ApiEx.Client directly; but this seems like kicking the can down the road. The crux of the issue lies in the ability to correctly identify the app-side, without having direct access to a CoreAPI that has been passed to us from the game, within the same scope.

ApacheTech commented 2 years ago

(Hopefully) Fixed in 2.1.0.