Fix #126131: GPv3: Crash when deleting everything in edit mode

Assert in debug build, allocated vertex buffer has garbage data when
total points in the drawing are zero, Nothing is copied to vertex buffers
from `copy_transformed_positions()`. To fix the crash, exit early when
the number of points is zero and execute `DRW_shgroup_call_no_cull`
macro when batch is non-null.

Pull Request: https://projects.blender.org/blender/blender/pulls/126134
This commit is contained in:
Pratik Borhade
2024-08-09 15:23:10 +02:00
committed by Falk David
parent f313fb4709
commit 4d572b216f
2 changed files with 10 additions and 3 deletions

View File

@@ -68,15 +68,18 @@ void OVERLAY_edit_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *ob)
DRWShadingGroup *lines_grp = pd->edit_grease_pencil_wires_grp;
if (lines_grp) {
blender::gpu::Batch *geom_lines = DRW_cache_grease_pencil_edit_lines_get(draw_ctx->scene, ob);
DRW_shgroup_call_no_cull(lines_grp, geom_lines, ob);
if (geom_lines) {
DRW_shgroup_call_no_cull(lines_grp, geom_lines, ob);
}
}
DRWShadingGroup *points_grp = pd->edit_grease_pencil_points_grp;
if (points_grp) {
blender::gpu::Batch *geom_points = DRW_cache_grease_pencil_edit_points_get(draw_ctx->scene,
ob);
DRW_shgroup_call_no_cull(points_grp, geom_points, ob);
if (geom_points) {
DRW_shgroup_call_no_cull(points_grp, geom_points, ob);
}
}
}

View File

@@ -750,6 +750,10 @@ static void grease_pencil_edit_batch_ensure(Object &object,
/* Add three for each bezier point, (one left, one right and one for the center point). */
total_line_points_num += total_bezier_point_num * 3;
if (total_points_num == 0) {
return;
}
GPU_vertbuf_data_alloc(*cache->edit_points_pos, total_points_num);
GPU_vertbuf_data_alloc(*cache->edit_points_selection, total_points_num);
GPU_vertbuf_data_alloc(*cache->edit_line_pos, total_line_points_num);