fix offset bug

The offset was being read after the block code, causing the offset to be off by 4 bytes.
This commit is contained in:
Josiah 2021-07-22 17:13:30 -05:00
parent 0ded5249d8
commit 01c051ce14
No known key found for this signature in database
GPG Key ID: C7BB8573A4ABC4B9

View File

@ -20,12 +20,13 @@ class Blendfile(io.FileIO):
block_offsets = {} block_offsets = {}
self.seek(self._block_start) self.seek(self._block_start)
while True: while True:
offset = self.tell()
# File block code; identifies type of data # File block code; identifies type of data
block_code = self.read(4).decode("utf-8") block_code = self.read(4).decode("utf-8")
# Empty string indicates EOF. # Empty string indicates EOF.
if block_code == "": if block_code == "":
break break
block_offsets[block_code] = self.tell() block_offsets[block_code] = offset
# Size of file block, after this header # Size of file block, after this header
block_size = int.from_bytes(self.read(4), self.endianness) block_size = int.from_bytes(self.read(4), self.endianness)
@ -100,7 +101,6 @@ class Blendfile(io.FileIO):
raise ValueError("I/O operation on a closed file.") raise ValueError("I/O operation on a closed file.")
# Grab SDNA index and struct count from file block header. # Grab SDNA index and struct count from file block header.
self.seek(offset + 4 + 4 + self.pointer_size) self.seek(offset + 4 + 4 + self.pointer_size)
sdna_index = int.from_bytes(self.read(4), self.endianness) sdna_index = int.from_bytes(self.read(4), self.endianness)
count = int.from_bytes(self.read(4), self.endianness) count = int.from_bytes(self.read(4), self.endianness)