Skip to content

Switching to Spectator throws exception #79

@dogfuntom

Description

@dogfuntom

Namely Index out of Bounds exception in the HandleCharacterSpawnRequests.SpawnCharacter().

Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00029] in :0
at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in :0
at HandleCharacterSpawnRequests.SpawnCharacter (GameWorld world, PlayerState owner, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, System.Int32 heroIndex, BundledResourceManager resourceSystem) [0x000ff] in :0
at HandleCharacterSpawnRequests.OnUpdate () [0x0008a] in :0
at Unity.Entities.ComponentSystem.InternalUpdate () [0x0002b] in :0
at Unity.Entities.ScriptBehaviourManager.Update () [0x00000] in :0
at CharacterModuleServer.HandleSpawnRequests () [0x0000b] in :0
at ServerGameWorld.ServerTickUpdate () [0x000aa] in :0
at ServerGameLoop.UpdateActiveState () [0x00016] in :0
at StateMachine`1[T].Update () [0x00000] in :0
at ServerGameLoop.Update () [0x000d7] in :0
at Game.Update () [0x0021e] in :0
16582: ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

I think it happens like this:

  1. Command spectator is typed.
  2. ClientGameLoop.CmdSpectator() does this:
    m_requestedPlayerSettings.characterType = isControllingSpectatorCam ? 0 : 1000;
  3. It's forwarded to GameModeSystemServer.OnUpdate() which too forwards it further:
    CharacterSpawnRequest.Create(PostUpdateCommands, charControl.characterType, predictedState.position, rotation, playerEntity);
  4. After some more forwarding the request is handled by HandleCharacterSpawnRequests.SpawnCharacter():
    heroIndex = Mathf.Min(heroIndex, heroTypeRegistry.entries.Count);
  5. There 2 heroes, so min(1000, 2) = 2. Unsurprisingly the next line fails with exception:
    var heroTypeAsset = heroTypeRegistry.entries[heroIndex];

Conclusion:

  1. Spectator command introduces special index 1000 that should mean spectator camera instead of normal hero.
  2. But no code further in the pipeline handles this special case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions