From f5acb6015b350edb236cda766c13aa776dcc4e95 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Fri, 6 Dec 2024 17:06:50 +0100 Subject: [PATCH] fix new_array --- wgpu/backends/wgpu_native/_api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wgpu/backends/wgpu_native/_api.py b/wgpu/backends/wgpu_native/_api.py index 8598d31e..4b2177ba 100644 --- a/wgpu/backends/wgpu_native/_api.py +++ b/wgpu/backends/wgpu_native/_api.py @@ -138,13 +138,18 @@ def _new_struct_p(ctype, **kwargs): def new_array(ctype, elements): assert ctype.endswith("[]") if isinstance(elements, int): + # elements == count return ffi.new(ctype, elements) elif elements: array = ffi.new(ctype, elements) # The array is a contiguous copy of the element structs. We don't need # to keep a reference to the elements, but we do to sub-structs and # sub-arrays of these elements. - _refs_per_struct[array] = [_refs_per_struct.get(el, None) for el in elements] + _refs_per_struct[array] = [ + _refs_per_struct.get(el, None) + for el in elements + if isinstance(el, ffi.CData) + ] return array else: return ffi.NULL