Fix #117132: GPv3: edit mode overlay memory leaks #10

Closed
casey-bianco-davis wants to merge 2 commits from GPv3-Fix-edit-mode-overlay-memory-leak into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

View File

@ -208,6 +208,15 @@ static void grease_pencil_edit_batch_ensure(Object &object,
GreasePencilBatchCache *cache = static_cast<GreasePencilBatchCache *>( GreasePencilBatchCache *cache = static_cast<GreasePencilBatchCache *>(
grease_pencil.runtime->batch_cache); grease_pencil.runtime->batch_cache);
if (cache->edit_points_pos != nullptr) {
return;
}
/* Should be discarded together. */
BLI_assert(cache->edit_points_pos == nullptr && cache->edit_line_indices == nullptr &&
cache->edit_points_indices == nullptr);
BLI_assert(cache->edit_points == nullptr && cache->edit_lines == nullptr);
/* Get the visible drawings. */ /* Get the visible drawings. */
const Array<ed::greasepencil::DrawingInfo> drawings = const Array<ed::greasepencil::DrawingInfo> drawings =
ed::greasepencil::retrieve_visible_drawings(scene, grease_pencil); ed::greasepencil::retrieve_visible_drawings(scene, grease_pencil);
@ -225,8 +234,10 @@ static void grease_pencil_edit_batch_ensure(Object &object,
&format_edit_points_selection, "selection", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); &format_edit_points_selection, "selection", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
} }
cache->edit_points_pos = GPU_vertbuf_create_with_format(&format_edit_points_pos); GPUUsageType vbo_flag = GPU_USAGE_STATIC | GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY;
cache->edit_points_selection = GPU_vertbuf_create_with_format(&format_edit_points_selection); cache->edit_points_pos = GPU_vertbuf_create_with_format_ex(&format_edit_points_pos, vbo_flag);
cache->edit_points_selection = GPU_vertbuf_create_with_format_ex(&format_edit_points_selection,
vbo_flag);
int total_points_num = 0; int total_points_num = 0;
for (const ed::greasepencil::DrawingInfo &info : drawings) { for (const ed::greasepencil::DrawingInfo &info : drawings) {
@ -371,6 +382,9 @@ static void grease_pencil_edit_batch_ensure(Object &object,
cache->edit_lines = GPU_batch_create( cache->edit_lines = GPU_batch_create(
GPU_PRIM_LINE_STRIP, cache->edit_points_pos, cache->edit_line_indices); GPU_PRIM_LINE_STRIP, cache->edit_points_pos, cache->edit_line_indices);
GPU_batch_vertbuf_add(cache->edit_lines, cache->edit_points_selection, false); GPU_batch_vertbuf_add(cache->edit_lines, cache->edit_points_selection, false);
/* Allow creation of buffer texture. */
GPU_vertbuf_use(cache->edit_points_pos);
GPU_vertbuf_use(cache->edit_points_selection);
cache->is_dirty = false; cache->is_dirty = false;
} }