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:
parent
0011db7f47
commit
9f1f314077
6 changed files with 50 additions and 25 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,11 @@ public class BufferWriter : IGenericWriter
|
|||
}
|
||||
}
|
||||
|
||||
public void Write(ReadOnlySpan<byte> bytes)
|
||||
public virtual void Write(byte[] bytes) => Write(bytes.AsSpan());
|
||||
|
||||
public virtual void Write(byte[] bytes, int offset, int count) => Write(bytes.AsSpan(offset, count));
|
||||
|
||||
public virtual void Write(ReadOnlySpan<byte> bytes)
|
||||
{
|
||||
var length = bytes.Length;
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class GenericEntityPersistence<T> : Persistence, IGenericEntityPersistenc
|
|||
public override void WriteSnapshot(string basePath)
|
||||
{
|
||||
IIndexInfo<Serial> indexInfo = new EntityTypeIndex(_name);
|
||||
EntityPersistence.WriteEntities(indexInfo, EntitiesBySerial, basePath,World.SerializedTypes, out _);
|
||||
EntityPersistence.WriteEntities(indexInfo, EntitiesBySerial, basePath,World.SerializedTypes);
|
||||
}
|
||||
|
||||
public virtual void DeserializeIndexes(string savePath, Dictionary<ulong, string> typesDb)
|
||||
|
|
|
|||
|
|
@ -121,6 +121,8 @@ public interface IGenericWriter
|
|||
}
|
||||
void Write(Map value) => Write((byte)(value?.MapIndex ?? 0xFF));
|
||||
void Write(Race value) => Write((byte)(value?.RaceIndex ?? 0xFF));
|
||||
void Write(byte[] bytes);
|
||||
void Write(byte[] bytes, int offset, int count);
|
||||
void Write(ReadOnlySpan<byte> bytes);
|
||||
unsafe void WriteEnum<T>(T value) where T : unmanaged, Enum
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue