diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-04-11 22:50:52 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-04-11 22:59:18 +0300 |
commit | 07cacb6d148d7124ba9b6865ca25d585e7d3e4fd (patch) | |
tree | f403222a7db564ba6a7caaac918934825d44759b /source | |
parent | c4f7f59c659f7d986e4a2602eff4135fc58cf2f1 (diff) |
Fix crash when creating a 'gpu.types.Buffer'
Buffer creation may crash when passed a PyBuffer with no `shape` defined.
(Which is common for strucs).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/gpu/gpu_py_buffer.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/source/blender/python/gpu/gpu_py_buffer.c b/source/blender/python/gpu/gpu_py_buffer.c index e0c20b64c63..82c9f8f1f04 100644 --- a/source/blender/python/gpu/gpu_py_buffer.c +++ b/source/blender/python/gpu/gpu_py_buffer.c @@ -394,9 +394,16 @@ static PyObject *pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args return NULL; } - if (pygpu_buffer_dimensions_tot_len_compare(shape, shape_len, pybuffer.shape, pybuffer.ndim)) { + Py_ssize_t *pybuffer_shape = pybuffer.shape; + Py_ssize_t pybuffer_ndim = pybuffer.ndim; + if (!pybuffer_shape) { + pybuffer_shape = &pybuffer.len; + pybuffer_ndim = 1; + } + + if (pygpu_buffer_dimensions_tot_len_compare(shape, shape_len, pybuffer_shape, pybuffer_ndim)) { buffer = pygpu_buffer_make_from_data( - init, pygpu_dataformat.value_found, pybuffer.ndim, shape, pybuffer.buf); + init, pygpu_dataformat.value_found, shape_len, shape, pybuffer.buf); } PyBuffer_Release(&pybuffer); |