[Bf-blender-cvs] [5f6fae9ad0b] blender2.8: Fix T57070, T57389, and other bbox-related issues with meshes.

Bastien Montagne noreply at git.blender.org
Sun Nov 25 18:50:08 CET 2018


Commit: 5f6fae9ad0bdb4184fb430d533dbbdec9c3da67f
Author: Bastien Montagne
Date:   Sun Nov 25 17:16:11 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB5f6fae9ad0bdb4184fb430d533dbbdec9c3da67f

Fix T57070, T57389, and other bbox-related issues with meshes.

Thinks whole bbox code needs a complete rewrite, one can see a lot of
old history in it, it has way too many functions doing
nearly-the-same-thing(c), it spreads in very inconsistent ways across a
lot of files, ... But have no time for this right now, and would not be
a good idea with Beta comming up close anyway.

So for now going the simple and (hopefully) sane & safe way: forbid
object-level functions to affect data-level bbox. Mesh and curve ones
would generate bbox in obdata instead of object, for some reason (all
other obdata types only use object's bbox ever). That may have been
working in old ages, but with CoW and threaded depsgraph this is just
calling for piles of issues.

===================================================================

M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/mesh.c

===================================================================

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])



More information about the Bf-blender-cvs mailing list