Hey.
So I keep getting a random NRE on this function, and I can't seem to figure out for the life of me what the problem is... I'm hoping you guys can because this has bewildered me.
Thanks, PsychoTea.Code:void UpdateScoreboard() { scoreboardList.Clear(); var items = from pair in points orderby pair.Value descending select pair; foreach (KeyValuePair<BasePlayer, int> pair in items) { string playerName = pair.Key.displayName; string text = string.Format(playerName + ", " + pair.Value); scoreboardList.Add(text); } string scoreboardListCsv = string.Join("\n", scoreboardList.ToArray()); foreach (BasePlayer playingPlayer in players) { if (playingPlayer.net.connection != null && !playingPlayer.IsSleeping()) { var obj4 = new Facepunch.ObjectList?(new Facepunch.ObjectList("Scoreboard")); CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = playingPlayer.net.connection }, null, "DestroyUI", obj4); var obj24 = new Facepunch.ObjectList?(new Facepunch.ObjectList(scoreGUI.Replace("{text}", scoreboardListCsv).Replace("{timeremaining}", gametimerint.ToString() + " seconds left"))); CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = playingPlayer.net.connection }, null, "AddUI", obj24); } } }
Resolving an NRE in my code (C#)
Discussion in 'Rust Development' started by PsychoTea, Oct 18, 2015.
-
Calytic Community Admin Community Mod
I don't know why we can't get trace logs for NRE's like this. But in any case, your best bet is to comment out each section of the code until you identify which line is causing the NRE by process of elimination. Nothing here really sticks out at me as a potential cause.
You might want to check the playingPlayer.net != null in addition to playingPlayer.net.connection. Just a thought.. -
The problem is with commenting parts out is the NRE is extremely random, and as it's part of a game mode it's very tedious to test.
Good idea on the playingPlayer.net != null, I'll try that.
