diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-04-30 09:22:51 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-04-30 09:29:03 +0300 |
commit | 2b723abea02c868d94623f4dd9e9b6775cb3aaab (patch) | |
tree | d97e06140092dbfc9a407a4bdfdc9925c23b8a0a /source/blender/blenkernel/intern | |
parent | ea17a92cd7040c0d63a4ed3a8a60cd8f0a3cb77e (diff) |
Object: improve on fix for Object.to_mesh() crash T86871
While fa7ddd0f43ea15dd19d81e7808de2bfe8cfc89ee fixed the reported issue,
the possibility of reusing runtime data during curve-to-mesh conversion
remained. Instead of treating the bounding-box as a special case,
clear all run-time data for temporary objects.
Ref D11026
Reviewed By: sergey
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_convert.c | 29 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 11 |
2 files changed, 27 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c index 1ec3b6a1cbf..e03a5f03fb5 100644 --- a/source/blender/blenkernel/intern/mesh_convert.c +++ b/source/blender/blenkernel/intern/mesh_convert.c @@ -1027,11 +1027,15 @@ static Object *object_for_curve_to_mesh_create(Object *object) * * Note that there are extra fields in there like bevel and path, but those are not needed during * conversion, so they are not copied to save unnecessary allocations. */ - if (object->runtime.curve_cache != NULL) { + if (temp_object->runtime.curve_cache == NULL) { temp_object->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for curve types"); + } + + if (object->runtime.curve_cache != NULL) { BKE_displist_copy(&temp_object->runtime.curve_cache->disp, &object->runtime.curve_cache->disp); } + /* Constructive modifiers will use mesh to store result. */ if (object->runtime.data_eval != NULL) { BKE_id_copy_ex( @@ -1059,15 +1063,17 @@ static Object *object_for_curve_to_mesh_create(Object *object) static void curve_to_mesh_eval_ensure(Object *object) { - if (object->runtime.curve_cache == NULL) { - object->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve"); - } Curve *curve = (Curve *)object->data; Curve remapped_curve = *curve; Object remapped_object = *object; - remapped_object.runtime.bb = NULL; + BKE_object_runtime_reset(&remapped_object); + remapped_object.data = &remapped_curve; + if (remapped_object.runtime.curve_cache == NULL) { + remapped_object.runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve"); + } + /* Clear all modifiers for the bevel object. * * This is because they can not be reliably evaluated for an original object (at least because @@ -1078,8 +1084,8 @@ static void curve_to_mesh_eval_ensure(Object *object) Object bevel_object = {{NULL}}; if (remapped_curve.bevobj != NULL) { bevel_object = *remapped_curve.bevobj; - bevel_object.runtime.bb = NULL; BLI_listbase_clear(&bevel_object.modifiers); + BKE_object_runtime_reset(&bevel_object); remapped_curve.bevobj = &bevel_object; } @@ -1087,8 +1093,8 @@ static void curve_to_mesh_eval_ensure(Object *object) Object taper_object = {{NULL}}; if (remapped_curve.taperobj != NULL) { taper_object = *remapped_curve.taperobj; - taper_object.runtime.bb = NULL; BLI_listbase_clear(&taper_object.modifiers); + BKE_object_runtime_reset(&taper_object); remapped_curve.taperobj = &taper_object; } @@ -1110,12 +1116,9 @@ static void curve_to_mesh_eval_ensure(Object *object) BKE_object_eval_assign_data(&remapped_object, &mesh_eval->id, true); } - MEM_SAFE_FREE(remapped_object.runtime.bb); - MEM_SAFE_FREE(taper_object.runtime.bb); - MEM_SAFE_FREE(bevel_object.runtime.bb); - - BKE_object_free_curve_cache(&bevel_object); - BKE_object_free_curve_cache(&taper_object); + BKE_object_runtime_free(&remapped_object); + BKE_object_runtime_free(&taper_object); + BKE_object_runtime_free(&taper_object); } static Mesh *mesh_new_from_curve_type_object(Object *object) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 82d99e980a4..912bd5a4d69 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -5114,6 +5114,17 @@ void BKE_object_runtime_reset_on_copy(Object *object, const int UNUSED(flag)) } /** + * The function frees memory used by the runtime data, but not the runtime field itself. + * + * The caller is expected to run #BKE_object_runtime_reset if the struct will be used again. + */ +void BKE_object_runtime_free(Object *object) +{ + /* Currently this is all that's needed. */ + BKE_object_free_derived_caches(object); +} + +/** * Find an associated armature object. */ static Object *obrel_armature_find(Object *ob) |