From 69e0e9f19fdd5dcbb4edd153351a85132c9298a0 Mon Sep 17 00:00:00 2001 From: Pratik Borhade Date: Fri, 9 Feb 2024 10:48:23 +0100 Subject: [PATCH] GPv3: Assert drawing before first frame Assert at `BLI_assert(active_layer.has_drawing_at(current_frame))` New keyframe is not added when brush draws on a frame which is before the first frame that actually contains the drawing. Pull Request: https://projects.blender.org/blender/blender/pulls/117983 --- .../editors/sculpt_paint/grease_pencil_draw_ops.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc b/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc index e5bc90f7759..75bd6e98af1 100644 --- a/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc +++ b/source/blender/editors/sculpt_paint/grease_pencil_draw_ops.cc @@ -167,9 +167,12 @@ static int grease_pencil_brush_stroke_invoke(bContext *C, wmOperator *op, const /* If auto-key is on and the drawing at the current frame starts before the current frame a new * keyframe needs to be inserted. */ - if (blender::animrig::is_autokey_on(scene) && active_layer.frame_key_at(current_frame) && - *active_layer.frame_key_at(current_frame) < current_frame) - { + const bool is_first = active_layer.sorted_keys().is_empty() || + (active_layer.sorted_keys().first() > current_frame); + const bool needs_new_drawing = is_first || + (*active_layer.frame_key_at(current_frame) < current_frame); + + if (blender::animrig::is_autokey_on(scene) && needs_new_drawing) { const ToolSettings *ts = CTX_data_tool_settings(C); if ((ts->gpencil_flags & GP_TOOL_FLAG_RETAIN_LAST) != 0) { /* For additive drawing, we duplicate the frame that's currently visible and insert it at the