mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Fix PVS NRE (#5900)
This commit is contained in:
@@ -43,7 +43,7 @@ END TEMPLATE-->
|
||||
|
||||
### Bugfixes
|
||||
|
||||
*None yet*
|
||||
* Fixed a server crash due to a `NullReferenceException` in PVS system when a player's local entity is also one of their view subscriptions.
|
||||
|
||||
### Other
|
||||
|
||||
|
||||
@@ -166,11 +166,11 @@ internal sealed partial class PvsSystem
|
||||
var session = pvsSession.Session;
|
||||
if (session.Status != SessionStatus.InGame)
|
||||
{
|
||||
pvsSession.Viewers = Array.Empty<Entity<TransformComponent, EyeComponent?>>();
|
||||
pvsSession.Viewers = Array.Empty<Entity<TransformComponent, EyeComponent?>>();
|
||||
return;
|
||||
}
|
||||
|
||||
// Fast path
|
||||
// The majority of players will have no view subscriptions
|
||||
if (session.ViewSubscriptions.Count == 0)
|
||||
{
|
||||
if (session.AttachedEntity is not {} attached)
|
||||
@@ -184,15 +184,21 @@ internal sealed partial class PvsSystem
|
||||
return;
|
||||
}
|
||||
|
||||
var count = session.ViewSubscriptions.Count;
|
||||
var i = 0;
|
||||
if (session.AttachedEntity is { } local)
|
||||
{
|
||||
Array.Resize(ref pvsSession.Viewers, session.ViewSubscriptions.Count + 1);
|
||||
if (!session.ViewSubscriptions.Contains(local))
|
||||
count += 1;
|
||||
|
||||
Array.Resize(ref pvsSession.Viewers, count);
|
||||
|
||||
// Attached entity is always the first viewer, to prioritize it and help reduce pop-in for the "main" eye.
|
||||
pvsSession.Viewers[i++] = (local, Transform(local), _eyeQuery.CompOrNull(local));
|
||||
}
|
||||
else
|
||||
{
|
||||
Array.Resize(ref pvsSession.Viewers, session.ViewSubscriptions.Count);
|
||||
Array.Resize(ref pvsSession.Viewers, count);
|
||||
}
|
||||
|
||||
foreach (var ent in session.ViewSubscriptions)
|
||||
@@ -200,6 +206,8 @@ internal sealed partial class PvsSystem
|
||||
if (ent != session.AttachedEntity)
|
||||
pvsSession.Viewers[i++] = (ent, Transform(ent), _eyeQuery.CompOrNull(ent));
|
||||
}
|
||||
|
||||
DebugTools.AssertEqual(i, pvsSession.Viewers.Length);
|
||||
}
|
||||
|
||||
private void ProcessVisibleChunks()
|
||||
|
||||
Reference in New Issue
Block a user