ChrisNZL / Tallowmere2

Changelog, issue tracker, and development knowledge for Tallowmere 2.
https://tallowmere2.com
13 stars 0 forks source link

T2.Game.AssignPlayerHUDs: IndexOutOfRangeException: Index was outside the bounds of the array. #1041

Closed ChrisNZL closed 2 years ago

ChrisNZL commented 2 years ago

Auto reports. 0.3.5b.

Feedback IDs (all from same user):

Error when trying to create or load a 3-player Couch Co-op game.

8:00:51, Frame 16510, LOG »  Loading SavedGame.003.t2...
8:00:51, Frame 16510, LOG »  Ruleset: Version_0_3_1. GameMode: MainStory

8:00:52, Frame 16570, EXCEPTION »  IndexOutOfRangeException: Index was outside the bounds of the array.
>>>>> CRITICAL ERROR >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

T2.Game.AssignPlayerHUDs ()
T2.DungeonRoom.Update ()

GameStates: ShowingTitleScreen, TransitioningToDungeonRoom
OnlineGameInfo: Device is offline.
No previous server nor online game info.
GameSetupMode: CouchCoop
Players: 3
DungeonRoomTransitioner.state: WaitingForRoomToLoad
DungeonRoom.state: PlacingPlayerCreatures
Room: 0 / 0
RoomModifiers: None
YouHaveDiedState: Null
SystemPlayer InputDevice: XInput Controller
HumanPlayer 1 InputDevice: 键盘
HumanPlayer 2 InputDevice: XInput Controller
HumanPlayer 3 InputDevice: XInput Controller
ChrisNZL commented 2 years ago

Fixed in 0.3.5c.

Unity was serializing an array, but with a Length of 2 due to mobile version, and it wasn't getting reset when switching to a desktop version.

#if GAME_CLIENT
    public HUD_Singleplayer[] couchCoopHuds = new HUD_Singleplayer[Platform.MaxCouchCoopPlayers];
#endif

Now, proper checks and initialization happen to the array within Game.OnAwake to ensure the array's Length is always correct for the platform.