diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 872b5074e4e..a4f348578f7 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -325,16 +325,22 @@ void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3]) BoundBox *BKE_curve_boundbox_get(Object *ob) { - Curve *cu = ob->data; + /* This is Object-level data access, DO NOT touch to Mesh's bb, would be totally thread-unsafe. */ + if (ob->bb == NULL || ob->bb->flag & BOUNDBOX_DIRTY) { + Curve *cu = ob->data; + float min[3], max[3]; - if (ob->bb) - return ob->bb; + INIT_MINMAX(min, max); + BKE_curve_minmax(cu, true, min, max); - if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) { - BKE_curve_texspace_calc(cu); + if (ob->bb == NULL) { + ob->bb = MEM_mallocN(sizeof(*ob->bb), __func__); + } + BKE_boundbox_init_from_minmax(ob->bb, min, max); + ob->bb->flag &= ~BOUNDBOX_DIRTY; } - return cu->bb; + return ob->bb; } void BKE_curve_texspace_calc(Curve *cu) diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 0942cb071a3..432d1fbc85b 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -914,16 +914,22 @@ void BKE_mesh_texspace_calc(Mesh *me) BoundBox *BKE_mesh_boundbox_get(Object *ob) { - Mesh *me = ob->data; + /* This is Object-level data access, DO NOT touch to Mesh's bb, would be totally thread-unsafe. */ + if (ob->bb == NULL || ob->bb->flag & BOUNDBOX_DIRTY) { + Mesh *me = ob->data; + float min[3], max[3]; - if (ob->bb) - return ob->bb; + INIT_MINMAX(min, max); + BKE_mesh_minmax(me, min, max); - if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) { - BKE_mesh_texspace_calc(me); + if (ob->bb == NULL) { + ob->bb = MEM_mallocN(sizeof(*ob->bb), __func__); + } + BKE_boundbox_init_from_minmax(ob->bb, min, max); + ob->bb->flag &= ~BOUNDBOX_DIRTY; } - return me->bb; + return ob->bb; } BoundBox *BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])