Fix #116734: Measure Tool Undo crash. #116751

Merged
Bastien Montagne merged 3 commits from mont29/blender:tmp-116734 into main 2024-01-12 11:13:51 +01:00
1 changed files with 20 additions and 4 deletions

View File

@ -515,11 +515,25 @@ static RulerItem *gzgroup_ruler_item_first_get(wmGizmoGroup *gzgroup)
}
#define RULER_ID "RulerData3D"
static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
/* GP data creation has to happen before the undo step is stored.
mont29 marked this conversation as resolved Outdated

Worth referencing #116734.

Worth referencing #116734.
* See also #116734. */
static void view3d_ruler_gpencil_ensure(bContext *C)
{
// RulerInfo *ruler_info = gzgroup->customdata;
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
if (scene->gpd == nullptr) {
scene->gpd = BKE_gpencil_data_addnew(bmain, "Annotations");
ideasman42 marked this conversation as resolved
Review

Note why this is needed.

Note why this is needed.
Review

Not sure what you mean? We are creating a new ID, and linking it to another ID, so we need to tag the modified ID for update... This is done in thousands of places all over our codebase, I would not expect to have to document this.

Actually, I also forgot to tag for relations update here.

Not sure what you mean? We are creating a new ID, and linking it to another ID, so we need to tag the modified ID for update... This is done in thousands of places all over our codebase, I would not expect to have to document this. Actually, I also forgot to tag for relations update here.
Review

Ah, no need then, I thought this might relate to undo (as tagging wasn't done before).

Ah, no need then, I thought this might relate to undo (as tagging wasn't done before).
DEG_id_tag_update_ex(bmain, &scene->id, ID_RECALC_COPY_ON_WRITE);
DEG_relations_tag_update(bmain);
}
}
static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
{
// RulerInfo *ruler_info = gzgroup->customdata;
Scene *scene = CTX_data_scene(C);
bGPdata *gpd;
bGPDlayer *gpl;
@ -529,9 +543,7 @@ static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
const char *ruler_name = RULER_ID;
bool changed = false;
if (scene->gpd == nullptr) {
scene->gpd = BKE_gpencil_data_addnew(bmain, "Annotations");
}
BLI_assert(scene->gpd != nullptr);
gpd = scene->gpd;
gpl = view3d_ruler_layer_get(gpd);
@ -1191,6 +1203,9 @@ static int gizmo_ruler_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
ruler_info->item_active = ruler_item_pick;
/* Ensures there is a valid GPencil data in current scene. */
view3d_ruler_gpencil_ensure(C);
return OPERATOR_RUNNING_MODAL;
}
@ -1419,6 +1434,7 @@ static int view3d_ruler_remove_invoke(bContext *C, wmOperator *op, const wmEvent
}
/* Update the annotation layer. */
view3d_ruler_gpencil_ensure(C);
view3d_ruler_to_gpencil(C, gzgroup);
ED_region_tag_redraw_editor_overlays(region);