diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc index be261fe513b..7606750c726 100644 --- a/source/blender/draw/intern/draw_cache_impl_curves.cc +++ b/source/blender/draw/intern/draw_cache_impl_curves.cc @@ -454,11 +454,14 @@ static void curves_batch_cache_ensure_procedural_indices(const bke::CurvesGeomet GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format); GPU_vertbuf_data_alloc(vbo, 1); - GPUIndexBuf *ibo = GPU_indexbuf_build_curves_on_device( - prim_type, curves.curves_num(), verts_per_curve); - + GPUIndexBuf *ibo = nullptr; + eGPUBatchFlag owns_flag = GPU_BATCH_OWNS_VBO; + if (curves.curves_num()) { + ibo = GPU_indexbuf_build_curves_on_device(prim_type, curves.curves_num(), verts_per_curve); + owns_flag |= GPU_BATCH_OWNS_INDEX; + } cache.final[subdiv].proc_hairs[thickness_res - 1] = GPU_batch_create_ex( - prim_type, vbo, ibo, GPU_BATCH_OWNS_VBO | GPU_BATCH_OWNS_INDEX); + prim_type, vbo, ibo, owns_flag); } static bool curves_ensure_attributes(const Curves &curves, diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc index f073939df18..57d76bf120c 100644 --- a/source/blender/gpu/intern/gpu_index_buffer.cc +++ b/source/blender/gpu/intern/gpu_index_buffer.cc @@ -270,7 +270,12 @@ GPUIndexBuf *GPU_indexbuf_build_curves_on_device(GPUPrimType prim_type, tris ? GPU_SHADER_INDEXBUF_TRIS : (lines ? GPU_SHADER_INDEXBUF_LINES : GPU_SHADER_INDEXBUF_POINTS)); GPU_shader_bind(shader); - GPUIndexBuf *ibo = GPU_indexbuf_build_on_device(curves_num * dispatch_x_dim); + int index_len = curves_num * dispatch_x_dim; + /* Buffer's size in bytes is required to be multiple of 16. + * Here is made an assumption that buffer's index_type is GPU_INDEX_U32. + * This will make buffer size multiple of 16 after multiplying by sizeof(uint32_t). */ + int multiple_of_4 = ceil_to_multiple_u(index_len, 4); + GPUIndexBuf *ibo = GPU_indexbuf_build_on_device(multiple_of_4); int resolution; if (tris) { resolution = 6;