[Bf-blender-cvs] [1c600cc6433] blender2.8: Object Mode: use obdata when loading from editmode

Campbell Barton noreply at git.blender.org
Tue Feb 6 08:01:04 CET 2018


Commit: 1c600cc643306c12f2bc652b2ea921ecbb3cfadf
Author: Campbell Barton
Date:   Tue Feb 6 15:47:51 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB1c600cc643306c12f2bc652b2ea921ecbb3cfadf

Object Mode: use obdata when loading from editmode

Avoids having to check the objects mode in 'update_from_editmode'.

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

M	source/blender/editors/object/object_edit.c
M	source/blender/makesrna/intern/rna_object_api.c

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

diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 1dc3f21afef..4b00852557f 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -58,6 +58,7 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_lattice_types.h"
 #include "DNA_workspace_types.h"
 
 #include "IMB_imbuf_types.h"
@@ -171,6 +172,9 @@ static bool ED_object_editmode_load_ex(Main *bmain, Object *obedit, const bool f
 
 	if (obedit->type == OB_MESH) {
 		Mesh *me = obedit->data;
+		if (me->edit_btmesh == NULL) {
+			return false;
+		}
 
 		if (me->edit_btmesh->bm->totvert > MESH_MAX_VERTS) {
 			error("Too many vertices");
@@ -184,15 +188,21 @@ static bool ED_object_editmode_load_ex(Main *bmain, Object *obedit, const bool f
 			MEM_freeN(me->edit_btmesh);
 			me->edit_btmesh = NULL;
 		}
-		if (obedit->restore_mode & OB_MODE_WEIGHT_PAINT) {
+		/* will be recalculated as needed. */
+		{
 			ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e');
 			ED_mesh_mirror_topo_table(NULL, NULL, 'e');
 		}
 	}
 	else if (obedit->type == OB_ARMATURE) {
+		const bArmature *arm = obedit->data;
+		if (arm->edbo == NULL) {
+			return false;
+		}
 		ED_armature_from_edit(obedit->data);
-		if (freedata)
+		if (freedata) {
 			ED_armature_edit_free(obedit->data);
+		}
 		/* TODO(sergey): Pose channels might have been changed, so need
 		 * to inform dependency graph about this. But is it really the
 		 * best place to do this?
@@ -200,20 +210,44 @@ static bool ED_object_editmode_load_ex(Main *bmain, Object *obedit, const bool f
 		DEG_relations_tag_update(bmain);
 	}
 	else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
+		const Curve *cu = obedit->data;
+		if (cu->editnurb == NULL) {
+			return false;
+		}
 		ED_curve_editnurb_load(obedit);
-		if (freedata) ED_curve_editnurb_free(obedit);
+		if (freedata) {
+			ED_curve_editnurb_free(obedit);
+		}
 	}
 	else if (obedit->type == OB_FONT) {
+		const Curve *cu = obedit->data;
+		if (cu->editfont == NULL) {
+			return false;
+		}
 		ED_curve_editfont_load(obedit);
-		if (freedata) ED_curve_editfont_free(obedit);
+		if (freedata) {
+			ED_curve_editfont_free(obedit);
+		}
 	}
 	else if (obedit->type == OB_LATTICE) {
+		const Lattice *lt = obedit->data;
+		if (lt->editlatt == NULL) {
+			return false;
+		}
 		ED_lattice_editlatt_load(obedit);
-		if (freedata) ED_lattice_editlatt_free(obedit);
+		if (freedata) {
+			ED_lattice_editlatt_free(obedit);
+		}
 	}
 	else if (obedit->type == OB_MBALL) {
+		const MetaBall *mb = obedit->data;
+		if (mb->editelems == NULL) {
+			return false;
+		}
 		ED_mball_editmball_load(obedit);
-		if (freedata) ED_mball_editmball_free(obedit);
+		if (freedata) {
+			ED_mball_editmball_free(obedit);
+		}
 	}
 
 	return true;
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 74528a2c0e8..17f19bfc38c 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -526,10 +526,8 @@ void rna_Object_dm_info(struct Object *ob, int type, char *result)
 
 static int rna_Object_update_from_editmode(Object *ob)
 {
-	if (ob->mode & OB_MODE_EDIT) {
-		return ED_object_editmode_load(ob);
-	}
-	return false;
+	/* fail gracefully if we aren't in edit-mode. */
+	return ED_object_editmode_load(ob);
 }
 #else /* RNA_RUNTIME */



More information about the Bf-blender-cvs mailing list