Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
164 stars 32 forks source link

TypeManager.static_pointer_array/TypeManager.dynamic_pointer_array are broken. #489

Open CookStar opened 1 year ago

CookStar commented 1 year ago

What pointer_attribute expects is CustomType not Array/BasePointer. https://github.com/Source-Python-Dev-Team/Source.Python/blob/0171b36297c23d480c17631561c98c0ff2afca28/addons/source-python/packages/source-python/memory/helpers.py#L235-L237

https://github.com/Source-Python-Dev-Team/Source.Python/blob/0171b36297c23d480c17631561c98c0ff2afca28/addons/source-python/packages/source-python/memory/manager.py#L496-L525

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'