fix: Fixes infinite loop in BinaryFileWriter (#1792)

### Summary
- Fixes infinite loop with binary file writer
- Removes extra buffer copying with binary file writer
- Removes storing type counts during world save file writing
- Fixes display cache self-deletion warning during world load
This commit is contained in:
Kamron Batman 2024-05-24 14:36:43 -07:00 committed by GitHub
parent 0011db7f47
commit 9f1f314077
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 25 deletions

View file

@ -47,6 +47,32 @@ public class BinaryFileWriter : BufferWriter, IDisposable
_file.Write(Buffer, 0, (int)Index);
Index = 0;
}
else
{
base.Flush(); // Increase buffer size
}
}
public override void Write(byte[] bytes) => Write(bytes, 0, bytes.Length);
public override void Write(byte[] bytes, int offset, int count)
{
if (Index > 0)
{
Flush();
}
_file.Write(bytes, offset, count);
}
public override void Write(ReadOnlySpan<byte> bytes)
{
if (Index > 0)
{
Flush();
}
_file.Write(bytes);
}
public override void Close()
@ -61,7 +87,10 @@ public class BinaryFileWriter : BufferWriter, IDisposable
public override long Seek(long offset, SeekOrigin origin)
{
Flush();
if (Index > 0)
{
Flush();
}
return _position = _file.Seek(offset, origin);
}