Open
Description
What pointer_attribute expects is CustomType not Array/BasePointer.
Source.Python/addons/source-python/packages/source-python/memory/helpers.py
Lines 235 to 237 in 0171b36
Source.Python/addons/source-python/packages/source-python/memory/manager.py
Lines 496 to 525 in 0171b36
And even if the Array inherits CustomType, the pointers set in the Array will be immediately discarded if not managed independently since the Array is dynamically created. (#490)
Code:
from memory.manager import CustomType
from memory.manager import TypeManager
type_manager = TypeManager()
class TestStaticPointerArray(CustomType, metaclass=type_manager):
_size = 4
static_vec_array = type_manager.static_pointer_array("Vector", 0, 1)
def test_static_pointer_array():
test = TestStaticPointerArray()
test.static_vec_array[0] = Vector(0.1, 0.1, 0.1)
print(test.static_vec_array[0])
test_static_pointer_array()
Output:
[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/plugins/command.py", line 164, in load_plugin
plugin = self.manager.load(plugin_name)
File "../addons/source-python/packages/source-python/plugins/manager.py", line 209, in load
plugin._load()
File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
self.module = import_module(self.import_name)
File "../addons/source-python/plugins/test/test.py", line 4703, in <module>
test_static_pointer_array()
File "../addons/source-python/plugins/test/test.py", line 4700, in test_static_pointer_array
test.static_vec_array[0] = Vector(0.1, 0.1, 0.1)
File "../addons/source-python/packages/source-python/memory/helpers.py", line 237, in __setitem__
self._make_attribute(index).__set__(self, value)
File "../addons/source-python/packages/source-python/memory/manager.py", line 505, in fset
ptr._pointer_values[offset] = value
AttributeError: 'Array' object has no attribute '_pointer_values'