Drake53/War3Net

Cannot access a closed stream

Closed this issue · 4 comments

Hi, getting this error when I try to build my map.

Unhandled exception. System.ObjectDisposedException: Cannot access a closed Stream. at System.IO.MemoryStream.Seek(Int64 offset, SeekOrigin loc) at War3Net.IO.Mpq.MpqStream.LoadSingleUnit() at War3Net.IO.Mpq.MpqStream.BufferData() at War3Net.IO.Mpq.MpqStream.ReadInternal(Byte[] buffer, Int32 offset, Int32 count) at System.IO.BinaryReader.InternalRead(Int32 numBytes) at System.IO.BinaryReader.ReadInt32() at War3Net.Build.Info.MapInfo.ReadFrom(BinaryReader reader) at War3Net.Build.Info.MapInfo..ctor(BinaryReader reader) at War3Net.Build.Extensions.BinaryReaderExtensions.ReadMapInfo(BinaryReader reader) at War3Net.Build.Extensions.MpqArchiveBuilderExtensions.SaveWithPreArchiveData(MpqArchiveBuilder mpqArchiveBuilder, String fileName, MpqArchiveCreateOptions createOptions) at War3Net.Build.MapBuilder.Build(String path, MpqArchiveCreateOptions createOptions) at AzerothWarsCSharp.Launcher.Program.Build(String baseMapPath, String projectFolderPath, Boolean launch) in C:\Users\Zak\source\repos\AzerothWarsCSharpNew\src\AzerothWarsCSharp.Launcher\Program.cs:line 146 at AzerothWarsCSharp.Launcher.Program.MakeDecision() in C:\Users\Zak\source\repos\AzerothWarsCSharpNew\src\AzerothWarsCSharp.Launcher\Program.cs:line 83 at AzerothWarsCSharp.Launcher.Program.Main() in C:\Users\Zak\source\repos\AzerothWarsCSharpNew\src\AzerothWarsCSharp.Launcher\Program.cs:line 59

This issue is new as of 5.4.2. If I downgrade to 5.4.1 the problem goes away.

Only changed that one thing in v5.4.2 so I think it's caused by a change in War3Net.IO.Mpq, War3Net.Build.Core v5.4.1 depended on War3Net.IO.Mpq v5.4.0, but latest version is v5.4.3
Since I skipped uploading v5.4.1 and v5.4.2 and nuget is being annoying about 2fa I'm attaching the packages here, I assume you know how to add a local folder source for nuget packages. Can you try out in which version the issue was introduced? (By using War3Net.Build v5.4.1 in combination with War3Net.IO.Mpq v5.4.1 / v5.4.2 / v5.4.3)
war3net.io.mpq.zip

Yep, no problem.
I only experience the issue with War3Net.IO.MPQ version 5.4.3. If I downgrade it to 5.4.2 or 5.4.1, everything works fine. I did all 3 of my tests with War3Net.Build 5.4.1 as instructed.

The issue was in War3Net.Build.Core after all, only occured since War3Net.IO.Mpq v5.4.3 because reading from the mpqstream for mpq files with SingleUnit flag (which includes files which are based on (in this case) a memorystream instead of an mpq archive) was made lazy so it happens on first read instead of in the ctor. At that point the base memorystream was already disposed.
Fixed in v5.4.3: 73cfc61

Awesome, I can compile again. Cheers. FYI I had to add War3Net.Build.Core 5.4.3 to my package references manually - the implicit reference from War3Net.Build 5.4.2 didn't seem to cut it.