blushiemagic / MagicStorage

A tModLoader mod for Terraria
MIT License
178 stars 101 forks source link

[Multiplayer] crafting sometimes eats items #209

Closed DefectiveNu closed 2 years ago

DefectiveNu commented 2 years ago

Happened twice, once to a friend and once to me (I was hosting via Host & Play)

Friend's issue was crafting Tungsten armor, I was crafting a max stack of wood platforms.

For mine, the stack seemed to appear but when I went to grab it, it seemed all the wood (ingredients section) disappeared and then came back, but then I didn't get my platforms, but the materials were used up.

Storage was about 2/3 full

Log from Tungsten armor crafting issue (nothing else within 1m of this):

[01:13:59.201] [Main Thread/WARN] [tML]: Silently Caught Exception: 
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at MagicStorage.Components.TEStorageUnit.WithdrawFromItemCollection(List`1 items, Item lookFor, Item& result, Boolean keepOneIfFavorite, Action`1 onItemRemoved, Action`2 onItemStackReduced) in MagicStorage\Components\TEStorageUnit.cs:line 183
   at MagicStorage.Components.TEStorageUnit.TryWithdraw(Item lookFor, Boolean locked, Boolean keepOneIfFavorite) in MagicStorage\Components\TEStorageUnit.cs:line 163
   at MagicStorage.Components.TEStorageHeart.Withdraw(Item lookFor, Boolean keepOneIfFavorite) in MagicStorage\Components\TEStorageHeart.cs:line 533
   at MagicStorage.CraftingGUI.HandleCraftWithdrawAndDeposit(TEStorageHeart heart, List`1 toWithdraw, List`1 results) in MagicStorage\CraftingGUI.cs:line 1390
   at MagicStorage.NetHelper.ReceiveCraftRequest(BinaryReader reader, Int32 sender) in MagicStorage\NetHelper.cs:line 650
   at Terraria.ModLoader.ModNet.HandleModPacket(BinaryReader reader, Int32 whoAmI, Int32 length) in tModLoader\Terraria\ModLoader\ModNet.cs:line 484
   at DMD<Terraria.MessageBuffer::GetData>(MessageBuffer this, Int32 start, Int32 length, Int32& messageType)
   at DMD<Terraria.NetMessage::CheckBytes>(Int32 bufferIndex)
   at Terraria.Netplay.UpdateServerInMainThread() in tModLoader\Terraria\Netplay.cs:line 64
   at Terraria.Main.DoUpdate(GameTime& gameTime) in tModLoader\Terraria\Main.cs:line 12797
   at Terraria.Main.Update(GameTime gameTime) in tModLoader\Terraria\Main.cs:line 12686
   at DMD<Terraria.Main::DedServ_PostModLoad>(Main this, Boolean& reloadMods)
   at Terraria.Main.DedServ() in tModLoader\Terraria\Main.cs:line 4202
   at Terraria.Program.LaunchGame_(Boolean isServer) in tModLoader\Terraria\Program.cs:line 237
   at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs) in tModLoader\Terraria\Program.cs:line 196
   at MonoLaunch.<>c__DisplayClass1_0.<Main>b__0() in tModLoader\Terraria\MonoLaunch.cs:line 52
   at System.Threading.Thread.StartCallback()

Log from platform crafting issue (also no other logs at the same time):

[01:38:07.485] [Main Thread/WARN] [tML]: Silently Caught Exception: 
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at MagicStorage.Components.TEStorageUnit.WithdrawFromItemCollection(List`1 items, Item lookFor, Item& result, Boolean keepOneIfFavorite, Action`1 onItemRemoved, Action`2 onItemStackReduced) in MagicStorage\Components\TEStorageUnit.cs:line 183
   at MagicStorage.Components.TEStorageUnit.TryWithdraw(Item lookFor, Boolean locked, Boolean keepOneIfFavorite) in MagicStorage\Components\TEStorageUnit.cs:line 163
   at MagicStorage.Components.TEStorageHeart.Withdraw(Item lookFor, Boolean keepOneIfFavorite) in MagicStorage\Components\TEStorageHeart.cs:line 533
   at MagicStorage.Components.TEStorageHeart.processClientOperations() in MagicStorage\Components\TEStorageHeart.cs:line 140
   at MagicStorage.Components.TEStorageHeart.Update() in MagicStorage\Components\TEStorageHeart.cs:line 110
   at Terraria.WorldGen.UpdateWorld_Inner() in tModLoader\Terraria\WorldGen.cs:line 46894
   at DMD<Terraria.WorldGen::UpdateWorld>()
   at DMD<Terraria.Main::DoUpdateInWorld>(Main this, Stopwatch sw)
   at Terraria.Main.DoUpdate(GameTime& gameTime) in tModLoader\Terraria\Main.cs:line 13131
   at Terraria.Main.Update(GameTime gameTime) in tModLoader\Terraria\Main.cs:line 12686
   at DMD<Terraria.Main::DedServ_PostModLoad>(Main this, Boolean& reloadMods)
   at Terraria.Main.DedServ() in tModLoader\Terraria\Main.cs:line 4202
   at Terraria.Program.LaunchGame_(Boolean isServer) in tModLoader\Terraria\Program.cs:line 237
   at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs) in tModLoader\Terraria\Program.cs:line 196
   at MonoLaunch.<>c__DisplayClass1_0.<Main>b__0() in tModLoader\Terraria\MonoLaunch.cs:line 52
   at System.Threading.Thread.StartCallback()

Mods/versions from the logs:

[21:42:13.295] [Main Thread/INFO] [tML]: Starting tModLoader server 1.4.3.6+2022.07.58.9|1.4-stable|Stable|8452bbdc2b0eb27aa26559ce3353b43d508fc6a4|5249649217585427496 built 8/17/2022 3:58 AM
[21:42:13.296] [Main Thread/INFO] [tML]: Running on Windows (v10.0.19044.0) X64 NetCore 6.0.0

[21:42:15.232] [Main Thread/DEBUG] [tML]: Network compatibility version is 2022.7.58
[21:42:16.000] [Main Thread/INFO] [tML]: Finding Mods...
[21:42:16.012] [Main Thread/INFO] [tML]: Sandboxing: AutoReroll (Auto Reforge) v2022.6.26
[21:42:16.078] [Main Thread/INFO] [tML]: Sandboxing: BetterBossBar (Better Boss Health Bar) v0.8
[21:42:16.104] [Main Thread/INFO] [tML]: Sandboxing: BetterChests (Better Chests) v1.6.1.1
[21:42:16.144] [Main Thread/INFO] [tML]: Sandboxing: BetterMultiplayer (Better Multiplayer) v1.6.2
[21:42:16.148] [Main Thread/INFO] [tML]: Sandboxing: Census (Census - Town NPC Checklist) v0.4.3
[21:42:16.172] [Main Thread/INFO] [tML]: Sandboxing: DPSExtreme (DPSExtreme) v0.2
[21:42:16.201] [Main Thread/INFO] [tML]: Sandboxing: FargoSeeds (Fargo's Best of Both Worlds) v0.2.1
[21:42:16.205] [Main Thread/INFO] [tML]: Sandboxing: InfiniteMunitions (Infinite Munitions) v1.0.3
[21:42:16.226] [Main Thread/INFO] [tML]: Sandboxing: MagicStorage (Magic Storage) v0.5.7.3
[21:42:16.312] [Main Thread/INFO] [tML]: Sandboxing: SubworldLibrary (Subworld Library) v2.0.1.2
[21:42:16.362] [Main Thread/INFO] [tML]: Sandboxing: Multiverse2 (Multiverse 2) v2.4.1
[21:42:16.417] [Main Thread/INFO] [tML]: Sandboxing: NoFishingQuests (Angler Shop) v2.2.1.1
[21:42:16.420] [Main Thread/INFO] [tML]: Sandboxing: OneStopNPCShop (The Shop Market) v1.2.1.3
[21:42:16.463] [Main Thread/INFO] [tML]: Sandboxing: PylonShield (Pylons Prevent Evils) v1.8.8
[21:42:16.565] [Main Thread/INFO] [tML]: Sandboxing: ReducedGrinding (Reduced Grinding) v8.4.1
[21:42:16.572] [Main Thread/INFO] [tML]: Sandboxing: SharedMap (Shared World Map) v0.1.2.5
[21:42:16.604] [Main Thread/INFO] [tML]: Sandboxing: StackableBuffDuration (Stackable Buff Duration) v1.0
absoluteAquarian commented 2 years ago

Huh, interesting. I found the problem code that's causing this issue. Thanks for reporting!

DefectiveNu commented 2 years ago

not sure if this will get seen but when withdrawing full stacks of crates, I got a similar error, and don't know if the same fix will fix this too:

[18:34:28.161] [Main Thread/WARN] [tML]: Silently Caught Exception: 
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at MagicStorage.Components.TEStorageUnit.WithdrawFromItemCollection(List`1 items, Item lookFor, Item& result, Boolean keepOneIfFavorite, Action`1 onItemRemoved, Action`2 onItemStackReduced) in MagicStorage\Components\TEStorageUnit.cs:line 183
   at MagicStorage.Components.TEStorageUnit.TryWithdraw(Item lookFor, Boolean locked, Boolean keepOneIfFavorite) in MagicStorage\Components\TEStorageUnit.cs:line 163
   at MagicStorage.Components.TEStorageHeart.Withdraw(Item lookFor, Boolean keepOneIfFavorite) in MagicStorage\Components\TEStorageHeart.cs:line 533
   at MagicStorage.Components.TEStorageHeart.processClientOperations() in MagicStorage\Components\TEStorageHeart.cs:line 140
   at MagicStorage.Components.TEStorageHeart.Update() in MagicStorage\Components\TEStorageHeart.cs:line 110
   at Terraria.WorldGen.UpdateWorld_Inner() in tModLoader\Terraria\WorldGen.cs:line 46894
   at DMD<Terraria.WorldGen::UpdateWorld>()
   at DMD<Terraria.Main::DoUpdateInWorld>(Main this, Stopwatch sw)
   at Terraria.Main.DoUpdate(GameTime& gameTime) in tModLoader\Terraria\Main.cs:line 13131
   at Terraria.Main.Update(GameTime gameTime) in tModLoader\Terraria\Main.cs:line 12686
   at DMD<Terraria.Main::DedServ_PostModLoad>(Main this, Boolean& reloadMods)
   at Terraria.Main.DedServ() in tModLoader\Terraria\Main.cs:line 4202
   at Terraria.Program.LaunchGame_(Boolean isServer) in tModLoader\Terraria\Program.cs:line 237
   at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs) in tModLoader\Terraria\Program.cs:line 196
   at MonoLaunch.<>c__DisplayClass1_0.<Main>b__0() in tModLoader\Terraria\MonoLaunch.cs:line 52
   at System.Threading.Thread.StartCallback()
absoluteAquarian commented 2 years ago

This stacktrace looks similar to to second stacktrace in the original post.

DefectiveNu commented 2 years ago

you know, I only compared it to the first trace, which had some references to crafting in it, while the 2nd didn't. Thanks for the quick reply