Commit: 15279c04d7946946f7b56f97783338958e4f2e0a Author: Bastien Montagne Date: Mon Jun 12 09:22:19 2017 +0200 Branches: soc-2017-normal-tools https://developer.blender.org/rB15279c04d7946946f7b56f97783338958e4f2e0a
Do not include BKE_mesh.h in bmesh_class.h We absolutely avoid such include unless totally mandatory, here we can simply keep lnorspaces array a pointer in BMesh struct, and allocate it on demand. Also, was breaking bmesh tests building. Note: this totally breaks undo/redo, but previous code was utterly wrong here as well (shallow copy of lnorspaces, ending up sharing whole internal memory -> crash garanteed ;) ). Think we can skip that struct for undo/redo for now at least, we can rebuild it in those cases imho... =================================================================== M source/blender/bmesh/bmesh_class.h M source/blender/bmesh/intern/bmesh_mesh.c M source/blender/editors/mesh/editmesh_tools.c M source/blender/editors/mesh/editmesh_undo.c M source/blender/editors/transform/transform.c =================================================================== diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h index a35bc2b3141..58079678454 100644 --- a/source/blender/bmesh/bmesh_class.h +++ b/source/blender/bmesh/bmesh_class.h @@ -20,8 +20,6 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include "BKE_mesh.h" - #ifndef __BMESH_CLASS_H__ #define __BMESH_CLASS_H__ @@ -40,6 +38,8 @@ struct BMEdge; struct BMLoop; struct BMFace; +struct MLoopNorSpaceArray; + struct BLI_mempool; /* note: it is very important for BMHeader to start with two @@ -256,7 +256,7 @@ typedef struct BMesh { void *py_handle; - MLoopNorSpaceArray bmspacearr; /* Stores MLoopNorSpaceArray for this BMesh */ + struct MLoopNorSpaceArray *bmspacearr; /* Stores MLoopNorSpaceArray for this BMesh */ char spacearr_dirty; } BMesh; diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index d6d61404b0e..6e2b65245c8 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -270,6 +270,8 @@ void BM_mesh_data_free(BMesh *bm) BLI_freelistN(&bm->selected); + MEM_SAFE_FREE(bm->bmspacearr); + BMO_error_clear(bm); } @@ -982,13 +984,15 @@ void BM_loops_calc_normal_vcos( void BM_lnorspacearr_store(BMesh *bm, float (*r_lnors)[3]) { + BLI_assert(bm->bmspacearr != NULL); + if (!CustomData_has_layer(&bm->ldata, CD_CUSTOMLOOPNORMAL)) { BM_data_layer_add(bm, &bm->ldata, CD_CUSTOMLOOPNORMAL); } int cd_loop_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL); - BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, M_PI, r_lnors, &bm->bmspacearr, NULL, cd_loop_clnors_offset, false); + BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, M_PI, r_lnors, bm->bmspacearr, NULL, cd_loop_clnors_offset, false); bm->spacearr_dirty &= ~(BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL); } @@ -1031,6 +1035,8 @@ void BM_lnorspace_invalidate(BMesh *bm, bool inval_all) void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor) { + BLI_assert(bm->bmspacearr != NULL); + if (!(bm->spacearr_dirty & (BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL))) { return; } @@ -1048,20 +1054,21 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor) } if (preserve_clnor) { - BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) { + BLI_assert(bm->bmspacearr->lspacearr != NULL); + BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) { BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) { if (BM_elem_flag_test(l, BM_ELEM_LNORSPACE)) { short(*clnor)[2] = BM_ELEM_CD_GET_VOID_P(l, cd_loop_clnors_offset); int l_index = BM_elem_index_get(l); - BKE_lnor_space_custom_data_to_normal(bm->bmspacearr.lspacearr[l_index], *clnor, oldnors[l_index]); + BKE_lnor_space_custom_data_to_normal(bm->bmspacearr->lspacearr[l_index], *clnor, oldnors[l_index]); } } } } - BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, M_PI, r_lnors, &bm->bmspacearr, NULL, cd_loop_clnors_offset, true); + BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, M_PI, r_lnors, bm->bmspacearr, NULL, cd_loop_clnors_offset, true); MEM_freeN(r_lnors); BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) { @@ -1072,12 +1079,12 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor) #if 0 short(*clnor)[2] = BM_ELEM_CD_GET_VOID_P(l, cd_loop_clnors_offset); int l_index = BM_elem_index_get(l); - BKE_lnor_space_custom_normal_to_data(bm->bmspacearr.lspacearr[l_index], l->v->no, *clnor); + BKE_lnor_space_custom_normal_to_data(bm->bmspacearr->lspacearr[l_index], l->v->no, *clnor); #else if (preserve_clnor) { short(*clnor)[2] = BM_ELEM_CD_GET_VOID_P(l, cd_loop_clnors_offset); int l_index = BM_elem_index_get(l); - BKE_lnor_space_custom_normal_to_data(bm->bmspacearr.lspacearr[l_index], oldnors[l_index], *clnor); + BKE_lnor_space_custom_normal_to_data(bm->bmspacearr->lspacearr[l_index], oldnors[l_index], *clnor); } #endif BM_elem_flag_disable(l, BM_ELEM_LNORSPACE); @@ -1092,7 +1099,10 @@ void BM_lnorspace_update(BMesh *bm) { float(*lnors)[3] = MEM_callocN(sizeof(*lnors) * bm->totloop, "__func__"); - if (bm->bmspacearr.lspacearr == NULL) { + if (bm->bmspacearr == NULL) { + bm->bmspacearr = MEM_callocN(sizeof(*bm->bmspacearr), __func__); + } + if (bm->bmspacearr->lspacearr == NULL) { BM_lnorspacearr_store(bm, lnors); } else if(bm->spacearr_dirty & (BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL)){ @@ -1117,12 +1127,15 @@ int BM_total_loop_select(BMesh *bm) void InitTransDataNormal(BMesh *bm, TransDataLoopNormal *tld, BMVert *v, BMLoop *l, int offset) { + BLI_assert(bm->bmspacearr != NULL); + BLI_assert(bm->bmspacearr->lspacearr != NULL); + int l_index = BM_elem_index_get(l); tld->loop_index = l_index; short *clnors_data = BM_ELEM_CD_GET_VOID_P(l, offset); float custom_normal[3]; - BKE_lnor_space_custom_data_to_normal(bm->bmspacearr.lspacearr[l_index], clnors_data, custom_normal); + BKE_lnor_space_custom_data_to_normal(bm->bmspacearr->lspacearr[l_index], clnors_data, custom_normal); tld->clnors_data = clnors_data; copy_v3_v3(tld->nloc, custom_normal); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 01fceb7c715..e1aaa06c5b2 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -54,6 +54,7 @@ #include "BKE_report.h" #include "BKE_texture.h" #include "BKE_main.h" +#include "BKE_mesh.h" #include "BKE_editmesh.h" #include "BLT_translation.h" @@ -6047,7 +6048,7 @@ static void apply_point_normals(bContext *C, wmOperator *op, float target[3], bo negate_v3(tld->nloc); } if (tld->loop_index != -1) { - BKE_lnor_space_custom_normal_to_data(bm->bmspacearr.lspacearr[tld->loop_index], tld->nloc, tld->clnors_data); + BKE_lnor_space_custom_normal_to_data(bm->bmspacearr->lspacearr[tld->loop_index], tld->nloc, tld->clnors_data); } } } diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index e036dd8b94c..953b4c1b0f5 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -491,7 +491,7 @@ static void *editbtMesh_to_undoMesh(void *emv, void *obdata) UndoMesh *um = MEM_callocN(sizeof(UndoMesh), "undo Mesh"); - um->bmspacearr = em->bm->bmspacearr; + um->bmspacearr = *em->bm->bmspacearr; um->spacearr_dirty = em->bm->spacearr_dirty; /* make sure shape keys work */ @@ -586,7 +586,7 @@ static void undoMesh_to_editbtMesh(void *um_v, void *em_v, void *obdata) bm->selectmode = um->selectmode; em->ob = ob; - bm->bmspacearr = um->bmspacearr; + *bm->bmspacearr = um->bmspacearr; bm->spacearr_dirty = um->spacearr_dirty; /* T35170: Restore the active key on the RealMesh. Otherwise 'fake' offset propagation happens diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 66fad1e36a7..b08d2c9bc31 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -63,6 +63,7 @@ #include "BKE_particle.h" #include "BKE_unit.h" #include "BKE_mask.h" +#include "BKE_mesh.h" #include "BKE_report.h" #include "BIF_gl.h" @@ -4235,7 +4236,7 @@ void freeCustomNormalArray(TransInfo *t, TransCustomData *custom_data) BMesh *bm = em->bm; for (int i = 0; i < ld->totloop; i++, tld++){ /* Restore custom loop normal on cancel */ - BKE_lnor_space_custom_normal_to_data(bm->bmspacearr.lspacearr[tld->loop_index], tld->niloc, tld->clnors_data); + BKE_lnor_space_custom_normal_to_data(bm->bmspacearr->lspacearr[tld->loop_index], tld->niloc, tld->clnors_data); } } @@ -4315,7 +4316,7 @@ static void applyNormalRotation(TransInfo *t, const int mval[2]) sub_v3_v3v3(vec, tld->nloc, tld->niloc); add_v3_v3v3(tld->nloc, tld->niloc, vec); - BKE_lnor_space_custom_normal_to_data(bm->bmspacearr.lspacearr[tld->loop_index], tld->nloc, tld->clnors_data); + BKE_lnor_space_custom_normal_to_data(bm->bmspacearr->lspacearr[tld->loop_index], tld->nloc, tld->clnors_data); } recalcData(t); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs