Path-of-Terraria / PathOfTerraria

GNU General Public License v3.0
1 stars 3 forks source link

`IndexOutOfRangeException` on Player Save #288

Closed steviegt6 closed 4 months ago

steviegt6 commented 4 months ago

Description

An exception: System.IndexOutOfRangeException: 'Index was outside the bounds of the array.', is thrown upon saving a player.

This appears to have been introduced in 30cb793b96b246f0306de321b9063cfded6836b9, a result of this code snippet https://github.com/Path-of-Terraria/PathOfTerraria/blob/main/Core/Systems/ModPlayers/GearSwapManager.cs#L48-L56. It's attempting to serialize a TagCompound[2] (TagCompound array) as an IList, which is unexpected as IList is only handled when the object also has a generic argument (such as List<T>).

Reproduction steps

  1. Create a new player.
  2. Exception is thrown as it is instantly saved.

OR

  1. Enter a world with a player.
  2. Save & exit from the world.
  3. Exception is thrown as it is saved.

Screenshots

image image

Logs

[21:58:37.894] [.NET TP Worker/ERROR] [tML]: Unhandled Exception
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Terraria.ModLoader.IO.TagIO.<>c.<.cctor>b__21_21(BinaryWriter w, IList v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 113
   at Terraria.ModLoader.IO.TagIO.PayloadHandler`1.Write(BinaryWriter w, Object v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 41
   at Terraria.ModLoader.IO.TagIO.WriteTag(String name, Object tag, BinaryWriter w) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 325
   at Terraria.ModLoader.IO.TagIO.<>c.<.cctor>b__21_24(BinaryWriter w, TagCompound v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 142
   at Terraria.ModLoader.IO.TagIO.PayloadHandler`1.Write(BinaryWriter w, Object v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 41
   at Terraria.ModLoader.IO.TagIO.WriteTag(String name, Object tag, BinaryWriter w) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 325
   at Terraria.ModLoader.IO.TagIO.<>c.<.cctor>b__21_24(BinaryWriter w, TagCompound v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 142
   at Terraria.ModLoader.IO.TagIO.PayloadHandler`1.WriteList(BinaryWriter w, IList list) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 55
   at Terraria.ModLoader.IO.TagIO.<>c.<.cctor>b__21_21(BinaryWriter w, IList v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 120
   at Terraria.ModLoader.IO.TagIO.PayloadHandler`1.Write(BinaryWriter w, Object v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 41
   at Terraria.ModLoader.IO.TagIO.WriteTag(String name, Object tag, BinaryWriter w) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 325
   at Terraria.ModLoader.IO.TagIO.<>c.<.cctor>b__21_24(BinaryWriter w, TagCompound v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 142
   at Terraria.ModLoader.IO.TagIO.PayloadHandler`1.Write(BinaryWriter w, Object v) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 41
   at Terraria.ModLoader.IO.TagIO.WriteTag(String name, Object tag, BinaryWriter w) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 325
   at Terraria.ModLoader.IO.TagIO.Write(TagCompound root, BinaryWriter writer) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 381
   at Terraria.ModLoader.IO.TagIO.ToStream(TagCompound root, Stream stream, Boolean compress) in tModLoader\Terraria\ModLoader\IO\TagIO.cs:line 377
   at Terraria.Utilities.FileUtilities.WriteTagCompound(String path, Boolean isCloud, TagCompound tag) in tModLoader\Terraria\Utilities\FileUtilities.TML.cs:line 124
   at Terraria.ModLoader.IO.PlayerIO.Save(TagCompound tag, String path, Boolean isCloudSave) in tModLoader\Terraria\ModLoader\IO\PlayerIO.cs:line 37
   at Terraria.Player.SavePlayerFile_Write(PlayerFileData playerFile, Byte[] plrData, TagCompound tplrData) in tModLoader\Terraria\Player.cs:line 44779
   at Terraria.Player.InternalSavePlayerFile(PlayerFileData playerFile) in tModLoader\Terraria\Player.cs:line 44736
   at Terraria.Player.<>c__DisplayClass1967_0.<SavePlayer>b__0() in tModLoader\Terraria\Player.cs:line 44694
   at Terraria.Utilities.FileUtilities.ProtectedInvoke(Action action) in tModLoader\Terraria\Utilities\FileUtilities.cs:line 207
   at DMD<System.Void Terraria.Player:SavePlayer(Terraria.IO.PlayerFileData, System.Boolean)>(PlayerFileData playerFile, Boolean skipMapSave)
   at SyncProxy<System.Void Terraria.Player:SavePlayer(Terraria.IO.PlayerFileData, System.Boolean)>(PlayerFileData , Boolean )
   at Terraria.WorldGen.SaveAndQuitCallBack(Object threadContext)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
steviegt6 commented 4 months ago

cc: @shnakamura