CitiesSkylinesMultiplayer / CSM

Source code for the Cities: Skylines Multiplayer mod (CSM)

Home Page:https://citiesskylinesmultiplayer.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Game crashes on connection due to PlayerLocationHandler

jdoubleu opened this issue · comments

Describe the bug

Whenever I play Cities Skylines Multiplayer with my friends at least one of the has a game crash when they try to join the server. Usually the last person, but not limited to, joining has this issues. We are playing as a group of 4. Sometimes retrying to connect multiple times resolves the issue.

Almost always I could pinpoint the issue to the PlayerLocationHandler. See Additional Context below for a detailed explanation.

To Reproduce

Steps to reproduce the behavior:

  1. The first player has to host the game/start the server.
  2. Let multiple player connect to the server.
  3. Wait a minute or two.
  4. Let the last player connect.
  5. See the game crash.

Expected behavior

The last player can, without any problems/crashes, connect to the server.

Actual behavior

The game crashes.

Sometimes the player doesn't even notice because the crash dialog does not pop in front of Cities Skylines, but in the background, causing confusion. This is more likely a problem with the game or the engine itself rather than this mod.

Additional context

I've analyzed the crash logs and enabled the debugging mode.

According to the error.log the game crashes with an Access Violation exception:

Unity Player [version: Unity 5.6.7f1_e80cc3114ac1]

Cities.exe caused an Access Violation (0xc0000005)
  in module Cities.exe at 0033:c0157449.

Error occurred at 2020-01-08_204526.
C:\SteamLibrary\steamapps\common\Cities_Skylines\Cities.exe, run by jdoubleu.
61% memory in use.
8135 MB physical memory [3122 MB free].
20423 MB paging file [11241 MB free].
134217728 MB user address space [134210493 MB free].
Read from location 00000000 caused an access violation.

...

Notice the 00000000 location. I guess this could be a NULL pointer, but I am not sure.

Following the output_log.txt a stack trace is printed at the very end of that file:

ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C0157449)
0x00007FF7C0157449 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C015945B)
0x00007FF7C015945B (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C013BDBB)
0x00007FF7C013BDBB (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C013C934)
0x00007FF7C013C934 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C013D8D3)
0x00007FF7C013D8D3 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C013DAB2)
0x00007FF7C013DAB2 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C01466A0)
0x00007FF7C01466A0 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C0146BFE)
0x00007FF7C0146BFE (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C00FE1D5)
0x00007FF7C00FE1D5 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C00FF677)
0x00007FF7C00FF677 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C00FF799)
0x00007FF7C00FF799 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C0102370)
0x00007FF7C0102370 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C0103552)
0x00007FF7C0103552 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7BFD222D6)
0x00007FF7BFD222D6 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C011926F)
0x00007FF7C011926F (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C011C909)
0x00007FF7C011C909 (Cities) 
  ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7C02C11AC)
0x00007FF7C02C11AC (Cities) 
0x000000003A69718C (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Shader:Find (string)
0x00000000BA2C7118 (Mono JIT Code) CSM.Commands.Handler.Internal.PlayerLocationHandler:Handle (CSM.Commands.Data.Internal.PlayerLocationCommand)
0x00000000BA2C6F45 (Mono JIT Code) CSM.Commands.Handler.CommandHandler`1<object>:Parse (CSM.Commands.CommandBase)
0x00000000BA2C2FBF (Mono JIT Code) CSM.Commands.CommandReceiver:Parse (LiteNetLib.NetPacketReader,LiteNetLib.NetPeer)
0x00000000BA2C2BFA (Mono JIT Code) CSM.Networking.Client:ListenerOnNetworkReceiveEvent (LiteNetLib.NetPeer,LiteNetLib.NetPacketReader,LiteNetLib.DeliveryMethod)
0x00000000BA2C2B8F (Mono JIT Code) LiteNetLib.EventBasedNetListener:LiteNetLib.INetEventListener.OnNetworkReceive (LiteNetLib.NetPeer,LiteNetLib.NetPacketReader,LiteNetLib.DeliveryMethod)
0x00000000BA2BD4F2 (Mono JIT Code) LiteNetLib.NetManager:ProcessEvent (LiteNetLib.NetEvent)
0x00000000BA2ACFA1 (Mono JIT Code) LiteNetLib.NetManager:PollEvents ()
0x00000000BA2ACE7A (Mono JIT Code) CSM.Networking.Client:ProcessEvents ()
0x00000000BA2ACDDC (Mono JIT Code) CSM.Networking.Client:<StartMainMenuEventProcessor>b__28_0 ()
0x00000000063008CB (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FFE87FD5CDF (mono) mono_set_defaults
0x00007FFE87F28499 (mono) mono_runtime_invoke
0x00007FFE87F538D7 (mono) mono_thread_interruption_request_flag
0x00007FFE88008955 (mono) unity_mono_reflection_method_get_method
0x00007FFEB36A7BD4 (KERNEL32) BaseThreadInitThunk
0x00007FFEB564CED1 (ntdll) RtlUserThreadStart

These SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' errors show up because the crash handler could not resolve the symbol names according to the Unity forums. They do not have todo with this bug and can therefore be ignored. I assume they happen because Cities Skylines is shipped with a release build of Unity. I could try to replace the release build with a debug build to obtain more details if you wish.

However the last known function call is 0x000000003A69718C (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Shader:Find (string). You can find such a call at PlayerLocationHandler.cs:32.

This aligns with the debugging output of the mod in multiplayer-logs/log-current.txt:

[20:45:07.2527] [1912.12.0.0] [Info] Attempting to patch Cities: Skylines using Harmony... 
[20:45:07.5487] [1912.12.0.0] [Info] Successfully patched Cities: Skylines! 
[20:45:07.5547] [1912.12.0.0] [Info] Creating join game button... 
[20:45:07.5547] [1912.12.0.0] [Info] Construction Complete! 
[20:45:15.9164] [1912.12.0.0] [Info] Creating join game button... 
[20:45:24.8867] [1912.12.0.0] [Info] Attempting to connect to server at <redacted address>... 
[20:45:24.9017] [1912.12.0.0] [Info] Set status to 'connecting'... 
[20:45:25.0887] [1912.12.0.0] [Info] Sending connection request to server... 
[20:45:25.0887] [1912.12.0.0] [Debug] Sending ConnectionRequestCommand to server 
[20:45:25.1077] [1912.12.0.0] [Debug] Received PlayerLocationCommand

The last received command is the PlayerLocationCommand.

The following is speculation. Since the stack trace continues I think the issue has something to do with Unity and that it cannot find or initialize the shader.

Related Issues

There is already an issue focusing on reworking the PlayerLocationCommand: #155.

My suggestion is to completely get rid of the handling logic if the player disabled the player location feature, at the beginning of PlayerLocationHandler.

A work around is when people are joining your server. Make sure no ones moves their in-game camera.

Excellent description, thanks! I'll take a further look this weekend.

Is this issue still a thing? if so i'll fix that in my PR #161 @jdoubleu

TBH I haven't played the game recently.

Assuming nothing changed in the PlayerLocationHandler, I'm confident this issue still exists.

I can try reproducing this issue once you've implemented the fixes in your PR to verify it got fixed.