DEBUGGED AND EDITED: I debugged my override method and found something even more odd. See my additional code below the original post:
I have posted a video showing a debug session which illustrates this problem. Sorry ahead of time if this goes against posting policy but I felt it was a best way to see the problem. Please let me know if anyone has any ideas of what is causing it. The "relevant" code is shown below. It may help to know that I am using a customized (modified) binary reader but even so, the fact that the issue occurs during an unrelated comparison when nothing is going on asyncronously during this debug session is completely baffling. If you want to see other code, just let me know and I will post it.
The relevant code (seen in the debug session) is:
public static RecordHeaderBase FromFile(BinaryReader reader, uint internalIDMask = 0xFFFFFFFF)
{
ModRecordConsolidator consolidator = reader.BaseStream as ModRecordConsolidator;
if (consolidator != null)
consolidator.EnableParseMode = true;
// my custom reader overrides the base read method. code shown below
RecordTypeInfo typeInfo = (RecordType)reader.ReadUInt32();
if (consolidator != null)
consolidator.EnableParseMode = false;
if (typeInfo == RecordType.TES4)
return new GameHeader(reader);
else if (typeInfo.isContainer)
return new GroupHeader(reader, typeInfo, internalIDMask);
else
return new RecordHeader(reader, typeInfo, internalIDMask);
}
Here is what you should know about "ParseMode". This binary reader has been modified to handle both reading and copying (writing to an output file) in a way that the input can be "prechecked" for specific patterns and modified before writing. "Parse Mode" is the mode that allows it to be read first without writing anything to the output file. The simple explanation is that when parse mode is inactive, the material is copied byte by byte to the destination file.
Here is the debug session: https://youtu.be/HJsVWFFw9a8
EDIT: Adding the "EnableParseMode" property code:
// parseMode is simply a boolean class field/variable
internal bool EnableParseMode { set { parseMode = value; } }
Additional OVERRIDE CODE WHERE THE EXTRA BYTES ARE READ:
public override int Read(byte[] array, int offset, int count)
{
int result;
if (compressionHeaderStream == null) // condition is true
{
result = base.Read(array, offset, count); // WHERE WEIRD SKIP BEHAVIOR OCCURS.
if (!parseMode) // condition is false so the block below is skipped
{
long equivalentBufferLocation = MemoryBufferStart + MemoryBuffer.Length;
if (Position > equivalentBufferLocation)
{
long bufferCopyBytes = Position - equivalentBufferLocation;
if (bufferCopyBytes > int.MaxValue)
throw new OverflowException();
offset += (count - (int)bufferCopyBytes);
MemoryBuffer.Write(array, offset, (int)bufferCopyBytes);
}
if (MaxBufferSize != 0)
if (MemoryBuffer.Length >= MaxBufferSize)
FlushToOutput();
}
}
else if (MemoryBuffer == null)
result = base.Read(array, offset, count);
else
result = MemoryBuffer.Read(array, offset, count);
return result;
}
For some reason the last update to Visual Studio did something to the debugger where it is not updating watched variables in debug session properly. However, during my series of 10+ debug sessions, I nailed down where the additional 3889 bytes are being "read"/ignored (the position simply advances as it does in the video). It occurs at place indicated in my comments. I have no idea why it advances here when it is only supposed to read 4 bytes. There are no further overrides to the base class (which is Microsoft provided).
User contributions licensed under CC BY-SA 3.0