Skip to content

Commit

Permalink
fix new_array
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Dec 6, 2024
1 parent 7e6e87e commit f5acb60
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion wgpu/backends/wgpu_native/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5acb60

Please sign in to comment.