ModAPI: null Reference CTD - Dedicated server entity gets out of sync with client
Since the last update I have found an issue where the player entitys are getting out of sync with the dedicated server in modAPI throwing null references and crashing the player to the desktop. The Issue only seems to impact dedicated server<->client gameplay, offline or self hosted gameplay does not seem to suffer from it in any major way.
Specifically in my case if i am using a .draw() related thing like billboard
Example:
Vector3D start = player.Character.GetPosition() + forward * dist + right * Math.Sin(angleH) * dist * 0.1 + up * Math.Sin(angleV) * dist * 0.1;
Vector3D dir = forward * rand.NextDouble() * 5; // Short streak direction (0-5m)
MyTransparentGeometry.AddLineBillboard(material, streakColor, start, dir, (float)dir.Length(), thickness, BlendTypeEnum.Standard);
OR
In the missionHUD system
Example:
MyAPIGateway.Utilities.GetObjectiveLine().Objectives.Clear();
MyAPIGateway.Utilities.GetObjectiveLine().Title = "Initialising";
MyAPIGateway.Utilities.GetObjectiveLine().Objectives.Add("Scanning..");
MyAPIGateway.Utilities.GetObjectiveLine().Show();
The player [entity(MyAPIGateway.Session.Player;)] reference seems to get out of date if a player dies or respawns. After respawning, the client side and server side entities seem to become out of sync in the client side, server side and/or local client instances. causing a Nullreference type Crash to desktop error on the next call to AddlLineBillboard or GetObjectiveLine() after the player finishes respawning.
I've attached one such error to this report in debug.txt
The issue seems to be a timing issue, because if you put in a really extreme timer delay the moment a player is detected as dead effectively halting any player entity calls/checks for a few seconds after the player respawns, the crash to desktop mostly does not occur anymore.
An example of such a hacky workaround fix in my UpdateAfterSimulation() which seems to mostly work is below:
//Client side kill switch if player is not spawned in yet halt all execution for 15 seconds
//after they respawn.
var player = MyAPIGateway.Session.Player;
if (player == null || player.Character == null || player.Character.IsDead)
{
killswitch = true;
base.UpdateAfterSimulation();
return;
} else if (killswitch)
{
if (counter >= 1500)
{
counter = 0;
killswitch = false;
}
counter++;
}
if (!killswitch) {
//all the rest of your mod's UpdateAfterSimulation() / UpdateBeforeSimulation() code needs to go in here
}
I have the same bug
Replies have been locked on this page!