From 07cacb6d148d7124ba9b6865ca25d585e7d3e4fd Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 11 Apr 2022 16:50:52 -0300 Subject: [PATCH] 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). --- source/blender/python/gpu/gpu_py_buffer.c | 11 +++++++++-- 1 file 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);