From a5c59fb90ef9c3e330556703c86e720740cf2c8d Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Mon, 15 Nov 2021 08:07:11 +0100 Subject: Fix T89260: Eevee crashes with custom node sockets. Cause of this issue is that Custom Node Sockets info type was initialized as SOCK_FLOAT when registering. Areas within the core that would ignore custom socket types by checking its type would use the socket as being a float type. When custom node sockets have a property called default_value blender tries to store it as an internal default value what failed in debug builds. This patch will set the socket type to SOCK_CUSTOM when registering a custom socket type and allow, but skip storage of custom default values. In this case the default values should already be stored as custom properies. Reviewed By: campbellbarton, JacquesLucke Maniphest Tasks: T89260 Differential Revision: https://developer.blender.org/D13174 --- source/blender/blenkernel/intern/node.cc | 4 +++- source/blender/makesrna/intern/rna_nodetree.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index cc8eadef149..ab3132a5d58 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -474,8 +474,10 @@ static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *so case SOCK_MATERIAL: BLO_write_struct(writer, bNodeSocketValueMaterial, sock->default_value); break; - case __SOCK_MESH: case SOCK_CUSTOM: + /* Custom node sockets where default_value is defined uses custom properties for storage. */ + break; + case __SOCK_MESH: case SOCK_SHADER: case SOCK_GEOMETRY: BLI_assert_unreachable(); diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 01889a1b0a9..e6b732aabd4 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -2805,6 +2805,7 @@ static StructRNA *rna_NodeSocket_register(Main *UNUSED(bmain), /* setup dummy socket & socket type to store static properties in */ memset(&dummyst, 0, sizeof(bNodeSocketType)); + dummyst.type = SOCK_CUSTOM; memset(&dummysock, 0, sizeof(bNodeSocket)); dummysock.typeinfo = &dummyst; -- cgit v1.2.3 From c3472cb11cded38b277f71ca9d7fc06c417da022 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Mon, 15 Nov 2021 12:17:11 +0100 Subject: Fix T93074: Gpencil cutter not using flat caps in middle cuts When cut an stroke using the option Flat Caps, the falt was not done if the cut was done in the middle of the stroke. Now the flat is applied to the segments created and also some cleanup of the code done. --- source/blender/blenkernel/BKE_gpencil_geom.h | 5 +++-- source/blender/blenkernel/intern/gpencil_geom.cc | 8 ++++++-- source/blender/editors/gpencil/annotate_paint.c | 2 +- source/blender/editors/gpencil/gpencil_convert.c | 2 +- source/blender/editors/gpencil/gpencil_edit.c | 12 ++++++------ source/blender/editors/gpencil/gpencil_merge.c | 3 ++- source/blender/editors/gpencil/gpencil_paint.c | 2 +- source/blender/editors/gpencil/gpencil_utils.c | 2 +- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h index a9cd553a8fe..41b1bba10ba 100644 --- a/source/blender/blenkernel/BKE_gpencil_geom.h +++ b/source/blender/blenkernel/BKE_gpencil_geom.h @@ -128,8 +128,9 @@ struct bGPDstroke *BKE_gpencil_stroke_delete_tagged_points(struct bGPdata *gpd, struct bGPDstroke *gps, struct bGPDstroke *next_stroke, int tag_flags, - bool select, - int limit); + const bool select, + const bool flat_cap, + const int limit); void BKE_gpencil_curve_delete_tagged_points(struct bGPdata *gpd, struct bGPDframe *gpf, struct bGPDstroke *gps, diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc index debdf44b0bb..fffc13c49a8 100644 --- a/source/blender/blenkernel/intern/gpencil_geom.cc +++ b/source/blender/blenkernel/intern/gpencil_geom.cc @@ -3122,8 +3122,9 @@ bGPDstroke *BKE_gpencil_stroke_delete_tagged_points(bGPdata *gpd, bGPDstroke *gps, bGPDstroke *next_stroke, int tag_flags, - bool select, - int limit) + const bool select, + const bool flat_cap, + const int limit) { tGPDeleteIsland *islands = (tGPDeleteIsland *)MEM_callocN( sizeof(tGPDeleteIsland) * (gps->totpoints + 1) / 2, "gp_point_islands"); @@ -3171,6 +3172,9 @@ bGPDstroke *BKE_gpencil_stroke_delete_tagged_points(bGPdata *gpd, for (idx = 0; idx < num_islands; idx++) { tGPDeleteIsland *island = &islands[idx]; new_stroke = BKE_gpencil_stroke_duplicate(gps, false, true); + if (flat_cap) { + new_stroke->caps[1 - (idx % 2)] = GP_STROKE_CAP_FLAT; + } /* if cyclic and first stroke, save to join later */ if ((is_cyclic) && (gps_first == nullptr)) { diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index bdb4e485373..bf53241a947 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -1195,7 +1195,7 @@ static void annotation_stroke_eraser_dostroke(tGPsdata *p, /* Second Pass: Remove any points that are tagged */ if (do_cull) { BKE_gpencil_stroke_delete_tagged_points( - p->gpd, gpf, gps, gps->next, GP_SPOINT_TAG, false, 0); + p->gpd, gpf, gps, gps->next, GP_SPOINT_TAG, false, false, 0); } } } diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index 406a7ac77fc..656fec565df 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -1834,7 +1834,7 @@ static int image_to_gpencil_exec(bContext *C, wmOperator *op) /* Delete any selected point. */ LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) { BKE_gpencil_stroke_delete_tagged_points( - gpd, gpf, gps, gps->next, GP_SPOINT_SELECT, false, 0); + gpd, gpf, gps, gps->next, GP_SPOINT_SELECT, false, false, 0); } BKE_reportf(op->reports, RPT_INFO, "Object created"); diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index f6012883e1f..3fc08096ab5 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -2635,7 +2635,7 @@ static int gpencil_delete_selected_points(bContext *C) else { /* delete unwanted points by splitting stroke into several smaller ones */ BKE_gpencil_stroke_delete_tagged_points( - gpd, gpf, gps, gps->next, GP_SPOINT_SELECT, false, 0); + gpd, gpf, gps, gps->next, GP_SPOINT_SELECT, false, false, 0); } changed = true; @@ -4656,11 +4656,11 @@ static int gpencil_stroke_separate_exec(bContext *C, wmOperator *op) /* delete selected points from destination stroke */ BKE_gpencil_stroke_delete_tagged_points( - gpd_dst, gpf_dst, gps_dst, NULL, GP_SPOINT_SELECT, false, 0); + gpd_dst, gpf_dst, gps_dst, NULL, GP_SPOINT_SELECT, false, false, 0); /* delete selected points from origin stroke */ BKE_gpencil_stroke_delete_tagged_points( - gpd_src, gpf, gps, gps->next, GP_SPOINT_SELECT, false, 0); + gpd_src, gpf, gps, gps->next, GP_SPOINT_SELECT, false, false, 0); } } /* selected strokes mode */ @@ -4839,11 +4839,11 @@ static int gpencil_stroke_split_exec(bContext *C, wmOperator *op) /* delete selected points from destination stroke */ BKE_gpencil_stroke_delete_tagged_points( - gpd, gpf, gps_dst, NULL, GP_SPOINT_SELECT, true, 0); + gpd, gpf, gps_dst, NULL, GP_SPOINT_SELECT, true, false, 0); /* delete selected points from origin stroke */ BKE_gpencil_stroke_delete_tagged_points( - gpd, gpf, gps, gps->next, GP_SPOINT_SELECT, false, 0); + gpd, gpf, gps, gps->next, GP_SPOINT_SELECT, false, false, 0); } } } @@ -5039,7 +5039,7 @@ static void gpencil_cutter_dissolve(bGPdata *gpd, } BKE_gpencil_stroke_delete_tagged_points( - gpd, hit_layer->actframe, hit_stroke, gpsn, GP_SPOINT_TAG, false, 1); + gpd, hit_layer->actframe, hit_stroke, gpsn, GP_SPOINT_TAG, false, flat_caps, 1); } } diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index 259b2882589..925c2e1cd7f 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -182,7 +182,8 @@ static void gpencil_dissolve_points(bContext *C) } LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) { - BKE_gpencil_stroke_delete_tagged_points(gpd, gpf, gps, gps->next, GP_SPOINT_TAG, false, 0); + BKE_gpencil_stroke_delete_tagged_points( + gpd, gpf, gps, gps->next, GP_SPOINT_TAG, false, false, 0); } } CTX_DATA_END; diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 8d72ea72532..f0118988559 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1699,7 +1699,7 @@ static void gpencil_stroke_eraser_dostroke(tGPsdata *p, } BKE_gpencil_stroke_delete_tagged_points( - p->gpd, gpf, gps, gps->next, GP_SPOINT_TAG, false, 0); + p->gpd, gpf, gps, gps->next, GP_SPOINT_TAG, false, false, 0); } gpencil_update_cache(p->gpd); } diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index f3c3aa10632..86df452f49a 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -3372,7 +3372,7 @@ bGPDstroke *ED_gpencil_stroke_join_and_trim( } /* Remove tagged points to trim stroke. */ gps_final = BKE_gpencil_stroke_delete_tagged_points( - gpd, gpf, gps_dst, gps_dst->next, GP_SPOINT_TAG, false, 0); + gpd, gpf, gps_dst, gps_dst->next, GP_SPOINT_TAG, false, false, 0); } /* Join both strokes. */ -- cgit v1.2.3 From 62da41d63dd9fb131a3c7a1f339b49e6186b3300 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 15 Nov 2021 08:52:58 -0600 Subject: Fix: Incorrect socket identifier versioning There were two issues: - The third math node socket does not exist in old enough files. - The comment incorrectly referred to the vector math node. Differential Revision: https://developer.blender.org/D13219 --- source/blender/blenloader/intern/versioning_300.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 6402bcc0b05..c0c3a8e4d4b 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -2158,8 +2158,8 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) * \note Keep this message at the bottom of the function. */ { - /* Use consistent socket identifiers for the vector math node. - * Thecode to make unique identifiers from the names was inconsitent. */ + /* Use consistent socket identifiers for the math node. + * The code to make unique identifiers from the names was inconsistent. */ FOREACH_NODETREE_BEGIN (bmain, ntree, id) { if (ELEM(ntree->type, NTREE_SHADER, NTREE_GEOMETRY)) { LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { @@ -2167,7 +2167,11 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) bNodeSocket *value1 = ((bNodeSocket *)node->inputs.first)->next; bNodeSocket *value2 = value1->next; strcpy(value1->identifier, "Value_001"); - strcpy(value2->identifier, "Value_002"); + if (value2 != NULL) { + /* This can be null when file is quite old so that the socket did not exist + * (before 0406eb110332a8). */ + strcpy(value2->identifier, "Value_002"); + } } } } -- cgit v1.2.3 From 10a6a540af31e1c96f13a0faee75e3c924a772e5 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 15 Nov 2021 18:03:53 +0100 Subject: Cleanup: remove unnecessary functions Those functions were more useful when `FieldInferencingInterface` was still declared further down in `node.cc`. --- source/blender/blenkernel/intern/node.cc | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index a5800819ae5..98c31eab7cd 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -130,10 +130,6 @@ static void node_socket_interface_free(bNodeTree *UNUSED(ntree), static void nodeMuteRerouteOutputLinks(struct bNodeTree *ntree, struct bNode *node, const bool mute); -static FieldInferencingInterface *node_field_inferencing_interface_copy( - const FieldInferencingInterface &field_inferencing_interface); -static void node_field_inferencing_interface_free( - const FieldInferencingInterface *field_inferencing_interface); static void ntree_init_data(ID *id) { @@ -246,7 +242,7 @@ static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c ntree_dst->interface_type = nullptr; if (ntree_src->field_inferencing_interface) { - ntree_dst->field_inferencing_interface = node_field_inferencing_interface_copy( + ntree_dst->field_inferencing_interface = new FieldInferencingInterface( *ntree_src->field_inferencing_interface); } @@ -301,7 +297,7 @@ static void ntree_free_data(ID *id) MEM_freeN(sock); } - node_field_inferencing_interface_free(ntree->field_inferencing_interface); + delete ntree->field_inferencing_interface; /* free preview hash */ if (ntree->previews) { @@ -4548,18 +4544,6 @@ void ntreeUpdateAllNew(Main *main) FOREACH_NODETREE_END; } -static FieldInferencingInterface *node_field_inferencing_interface_copy( - const FieldInferencingInterface &field_inferencing_interface) -{ - return new FieldInferencingInterface(field_inferencing_interface); -} - -static void node_field_inferencing_interface_free( - const FieldInferencingInterface *field_inferencing_interface) -{ - delete field_inferencing_interface; -} - namespace blender::bke::node_field_inferencing { static bool is_field_socket_type(eNodeSocketDatatype type) -- cgit v1.2.3