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] Crash on world gen start (seems linked to mod combination) #26

Closed NovaNine closed 2 years ago

NovaNine commented 2 years ago

Describe the Bug: This issue seems correlated with having both Campaign Cartographer (2.1.1) and Ancient Tools (1.4.0) enabled, however the only exception I see is CC so I am posting it here.

I generate a new world and as it is about to start the game it says 8.3.2022 10:13:09 [Notification] Server stop requested, begin shutdown sequence. Stop reason: Exception thrown by server during startup or process however, I don't find any exceptions in the server logs, but rather one in the client log which references CC (see below)

After this the game is left unable to read the save file until restarted (long wait to see world list, shows as corrupted, but will load after a restart). I suspect an unclosed file handle?

To Reproduce: I'm using single player, 1.16.4 (stable) on Win 10. This happened multiple times when I generated a new world (settings). Happened with both 2.1.0 (yesterday) and 2.1.1 (today)

Though my number of tests was limited, this happened 4/4 times with my full mod list (see below). It happened 1/1 with just Alchemy, CC and Ancient Tools. It happened 2/2 with just CC and Ancient Tools. It did not happen 1/1 with just CC as my only mod. It did not happen 1/1 with my full mod list except Ancient Tools.

The same exception is thrown by CC if I attempt to load one of the failing worlds after I turn off Ancient Tools.

Expected Behaviour: I expect the game to start after world generation.

Additional Context 8.3.2022 10:13:09 [Fatal] System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'Vintagestory.Server.ServerCoreAPI' to type 'Vintagestory.API.Client.ICoreClientAPI'. at ApacheTech.VintageMods.CampaignCartographer.Features.PlayerPins.Patches.PlayerPinsPatches.Patch_PlayerMapLayer_Constructor_Postfix(ICoreAPI api, IWorldMapManager mapsink) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at Vintagestory.GameContent.WorldMapManager.OnLoaded() at Vintagestory.Server.ServerEventAPI.OnServerStage(EnumServerRunPhase runPhase) at Vintagestory.Server.ServerMain.EnterRunPhase(EnumServerRunPhase runPhase) at Vintagestory.Server.ServerMain.Launch() at _TRhArnJABwZoV9Vt7Ld2l65Xzgg._55FJfeMcDB5NT6lsb5fDE3bzUPI()

My mod list (ignore the Linux format, I am running the game on Windows 10, just used WSL to copy paste directory content):

-rwxrwxrwx 1 nova nova 899K Mar  7 16:03 AncientTools_V1.4.0.zip
-rwxrwxrwx 1 nova nova 496K Mar  8 10:08 ApacheTech.VintageMods.CampaignCartographer_v2.1.1.zip
-rwxrwxrwx 1 nova nova  33K Mar  7 16:20 CarryCapacity-VS1.16.0-v0.6.5.zip
-rwxrwxrwx 1 nova nova 1.8M Mar  8 00:27 CreaturesandCritters1.1.8.zip
-rwxrwxrwx 1 nova nova 128K Mar  7 16:13 FromGoldenCombs-v1.3.6-rc.5.zip
-rwxrwxrwx 1 nova nova 999K Mar  7 16:09 PackAnimals1.0.0.zip
-rwxrwxrwx 1 nova nova 145K Mar  7 16:48 VSHUD.dll
-rwxrwxrwx 1 nova nova 528K Mar  7 16:18 ViesCraftMachines-VS1.16.4-v1.9.0.zip
-rwxrwxrwx 1 nova nova 1.5M Mar  7 16:00 alchemy-1.6.0.zip
-rwxrwxrwx 1 nova nova 657K Mar  7 16:36 cats_v1.3.4_petai_v1.3.+.zip
-rwxrwxrwx 1 nova nova 150K Mar  7 16:33 hudclock-2.7.0.zip
-rwxrwxrwx 1 nova nova 1.1M Mar  7 16:08 petai_v1.3.6.zip
-rwxrwxrwx 1 nova nova 383K Mar  7 16:06 wildcraft-v1.2.1.zip

Edit: Fixed name of Ancient Tools (initially had typed Primitive Tools)

NovaNine commented 2 years ago

Looks like the link to Ancient Tools may have been wrong after all. I got the same error after a clean restart, with AT completely disabled. I generated one world successfully, then exited to menu and generated another and it errored same as above.

ApacheTech commented 2 years ago

Ok. This is code that's running on the server, and shouldn't be. It's a constant problem with this game, due to the way it handles server and client side code.

Could I ask, does this happen when you add the mod to an existing world, or only when you gen a new world?

ApacheTech commented 2 years ago

I've just generated 10 different worlds with your settings, with CC and Ancient Tools enabled. I couldn't get it to crash. However, the bug is an obvious one... it's just very confusing. Harmony isn't loaded on the server at all. The server should never know about that code. This is one of the inconsistencies with the game. When you start a new world, the server and client are somewhat merged, until you log out, and back in again.

Either way, I've added a guard-clause to the patch, to force it to return early if it's ever run on the server. I'll release a hotfix now.

NovaNine commented 2 years ago

It does happen on a pre-existing world, it also happened on loading a world that worked earlier. So maybe the whole thing is random. Here's what I've done:

Earlier I was able to generate a world (CC+other mods) and played it for an hour. Saved and exited to menu, but did not close the game. Tried to re-enter it, got this error (same mods as when world generated).

I restarted the game and created a test world with just the core "mods" enabled. Gen worked. Saved, exited to menu, re-entered - ok. Saved, exited to menu. Enabled just CC (in addition to "core"). Entered OK. Saved, exited to menu. Changed nothing, error happened.

ApacheTech commented 2 years ago

This should hopefully be fixed in 2.1.2.

Update to 2.1.2 (Hotfix)

Fixed: Rare server crash when generating new single-player worlds.
ApacheTech commented 2 years ago

I've also made a bug report, and API suggestion on the official VS Discord.

NovaNine commented 2 years ago

Thank you very much! Fix seems 100% after multiple new gens / loads of existing worlds.