add in asserts when rv3d->viewmatob, rv3d->persmatob are not initialized.

This is often hard to spot since in many cases it works correctly even
when not initialized but may still fail in other situations.
This commit is contained in:
2013-05-08 13:00:52 +00:00
parent a4634bfe67
commit 562ed2b42e
8 changed files with 64 additions and 8 deletions

View File

@@ -245,9 +245,19 @@ double double_round(double x, int ndigits);
BLI_assert((fabsf(_test_unit - 1.0f) < BLI_ASSERT_UNIT_EPSILON) || \
(fabsf(_test_unit) < BLI_ASSERT_UNIT_EPSILON)); \
} (void)0
# define BLI_ASSERT_ZERO_M3(m) { \
BLI_assert(dot_vn_vn((const float *)m, (const float *)m, 9) != 0.0); \
} (void)0
# define BLI_ASSERT_ZERO_M4(m) { \
BLI_assert(dot_vn_vn((const float *)m, (const float *)m, 16) != 0.0); \
} (void)0
#else
# define BLI_ASSERT_UNIT_V2(v) (void)0
# define BLI_ASSERT_UNIT_V3(v) (void)0
# define BLI_ASSERT_UNIT_V2(v) (void)(v)
# define BLI_ASSERT_UNIT_V3(v) (void)(v)
# define BLI_ASSERT_ZERO_M3(m) (void)(m)
# define BLI_ASSERT_ZERO_M4(m) (void)(m)
#endif
#endif /* __BLI_MATH_BASE_H__ */

View File

@@ -276,7 +276,13 @@ int ED_operator_rv3d_user_region_poll(struct bContext *C);
void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d);
void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d);
#ifdef DEBUG
void ED_view3d_clear_mats_rv3d(struct RegionView3D *rv3d);
void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d);
#else
# define ED_view3d_clear_mats_rv3d(rv3d) (void)(rv3d)
# define ED_view3d_check_mats_rv3d(rv3d) (void)(rv3d)
#endif
int ED_view3d_scene_layer_set(int lay, const int *values, int *active);
bool ED_view3d_context_activate(struct bContext *C);

View File

@@ -587,6 +587,8 @@ BMFace *EDBM_face_find_nearest(ViewContext *vc, float *r_dist)
data.dist = FLT_MAX;
data.toFace = efa;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
mesh_foreachScreenFace(vc, findnearestface__getDistance, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
if ((vc->em->selectmode == SCE_SELECT_FACE) || (data.dist < *r_dist)) { /* only faces, no dist check */
@@ -613,14 +615,13 @@ BMFace *EDBM_face_find_nearest(ViewContext *vc, float *r_dist)
data.dist = *r_dist;
data.closest = NULL;
data.closestIndex = 0;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
data.pass = 0;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
mesh_foreachScreenFace(vc, findnearestface__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
if (data.dist > 3.0f) {
data.pass = 1;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
mesh_foreachScreenFace(vc, findnearestface__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
}

View File

@@ -2097,7 +2097,9 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt)
/* being set in code below */
arm->layer_used = 0;
ED_view3d_check_mats_rv3d(rv3d);
/* envelope (deform distance) */
if (arm->drawtype == ARM_ENVELOPE) {
/* precalc inverse matrix for drawing screen aligned */

View File

@@ -7001,6 +7001,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
if ((base->flag & OB_FROMDUPLI) ||
(v3d->flag2 & V3D_RENDER_OVERRIDE))
{
ED_view3d_clear_mats_rv3d(rv3d);
return;
}
@@ -7144,6 +7145,8 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
}
free_old_images();
ED_view3d_clear_mats_rv3d(rv3d);
}
/* ***************** BACKBUF SEL (BBS) ********* */

View File

@@ -243,6 +243,21 @@ void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d)
glMultMatrixf(ob->obmat);
}
#ifdef DEBUG
/* ensure we correctly initialize */
void ED_view3d_clear_mats_rv3d(struct RegionView3D *rv3d)
{
zero_m4(rv3d->viewmatob);
zero_m4(rv3d->persmatob);
}
void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d)
{
BLI_ASSERT_ZERO_M4(rv3d->viewmatob);
BLI_ASSERT_ZERO_M4(rv3d->persmatob);
}
#endif
/* ******************** default callbacks for view3d space ***************** */
static SpaceLink *view3d_new(const bContext *C)

View File

@@ -112,6 +112,8 @@ void meshobject_foreachScreenVert(
foreachScreenObjectVert_userData data;
DerivedMesh *dm = mesh_get_derived_deform(vc->scene, vc->obact, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
data.vc = *vc;
data.func = func;
data.userData = userData;
@@ -151,6 +153,8 @@ void mesh_foreachScreenVert(
foreachScreenVert_userData data;
DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
data.vc = *vc;
data.func = func;
data.userData = userData;
@@ -203,6 +207,8 @@ void mesh_foreachScreenEdge(
foreachScreenEdge_userData data;
DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
data.vc = *vc;
data.win_rect.xmin = 0;
@@ -247,13 +253,13 @@ void mesh_foreachScreenFace(
foreachScreenFace_userData data;
DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
data.vc = *vc;
data.func = func;
data.userData = userData;
data.clip_flag = clip_flag;
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
EDBM_index_arrays_ensure(vc->em, BM_FACE);
dm->foreachMappedFaceCenter(dm, mesh_foreachScreenFace__mapFunc, &data);
@@ -272,6 +278,8 @@ void nurbs_foreachScreenVert(
int i;
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
ED_view3d_check_mats_rv3d(vc->rv3d);
if (clip_flag & V3D_PROJ_TEST_CLIP_BB) {
ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
}
@@ -339,6 +347,8 @@ void mball_foreachScreenElem(
MetaBall *mb = (MetaBall *)vc->obedit->data;
MetaElem *ml;
ED_view3d_check_mats_rv3d(vc->rv3d);
for (ml = mb->editelems->first; ml; ml = ml->next) {
float screen_co[2];
if (ED_view3d_project_float_object(vc->ar, &ml->x, screen_co, clip_flag) == V3D_PROJ_RET_OK) {
@@ -361,6 +371,8 @@ void lattice_foreachScreenVert(
float *co = dl ? dl->verts : NULL;
int i, N = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
ED_view3d_check_mats_rv3d(vc->rv3d);
if (clip_flag & V3D_PROJ_TEST_CLIP_BB) {
ED_view3d_clipping_local(vc->rv3d, obedit->obmat); /* for local clipping lookups */
}
@@ -386,6 +398,8 @@ void armature_foreachScreenBone(
bArmature *arm = vc->obedit->data;
EditBone *ebone;
ED_view3d_check_mats_rv3d(vc->rv3d);
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
if (EBONE_VISIBLE(arm, ebone)) {
float screen_co_a[2], screen_co_b[2];
@@ -429,6 +443,8 @@ void pose_foreachScreenBone(
bPose *pose = vc->obact->pose;
bPoseChannel *pchan;
ED_view3d_check_mats_rv3d(vc->rv3d);
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
if (PBONE_VISIBLE(arm, pchan->bone)) {
float screen_co_a[2], screen_co_b[2];

View File

@@ -237,6 +237,7 @@ eV3DProjStatus ED_view3d_project_short_global(const ARegion *ar, const float co[
eV3DProjStatus ED_view3d_project_short_object(const ARegion *ar, const float co[3], short r_co[2], const eV3DProjTest flag)
{
RegionView3D *rv3d = ar->regiondata;
ED_view3d_check_mats_rv3d(rv3d);
return ED_view3d_project_short_ex(ar, rv3d->persmatob, true, co, r_co, flag);
}
@@ -250,6 +251,7 @@ eV3DProjStatus ED_view3d_project_int_global(const ARegion *ar, const float co[3]
eV3DProjStatus ED_view3d_project_int_object(const ARegion *ar, const float co[3], int r_co[2], const eV3DProjTest flag)
{
RegionView3D *rv3d = ar->regiondata;
ED_view3d_check_mats_rv3d(rv3d);
return ED_view3d_project_int_ex(ar, rv3d->persmatob, true, co, r_co, flag);
}
@@ -263,6 +265,7 @@ eV3DProjStatus ED_view3d_project_float_global(const ARegion *ar, const float co[
eV3DProjStatus ED_view3d_project_float_object(const ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag)
{
RegionView3D *rv3d = ar->regiondata;
ED_view3d_check_mats_rv3d(rv3d);
return ED_view3d_project_float_ex(ar, rv3d->persmatob, true, co, r_co, flag);
}