Add 'strict pointer mode' to BlendFile

Add a 'strict pointer mode' to the `BlendFile` class, which is enabled
by default. This allows users of the `BlendFile` class to decide whether
a bad pointer (i.e. one that points to a non-existing datablock) returns
`None` or raises a `SegmentationFault` exception.
This commit is contained in:
Sybren A. Stüvel
2021-07-22 10:28:48 +02:00
parent 803c38dac1
commit 087ff25c76
3 changed files with 45 additions and 7 deletions
+9
View File
@@ -217,6 +217,15 @@ class PointerTest(AbstractBlendFileTest):
with self.assertRaises(exceptions.SegmentationFault):
scene.get_pointer(b"ed")
def test_disabled_strict_pointer_mode(self):
scene = self.bf.code_index[b"SC"][0]
ed_ptr = scene.get(b"ed")
del self.bf.block_from_addr[ed_ptr]
self.bf.strict_pointer_mode = False
dereferenced = scene.get_pointer(b"ed")
self.assertIsNone(dereferenced)
def test_abs_offset(self):
scene = self.bf.code_index[b"SC"][0]
ed = scene.get_pointer(b"ed")