Assert CustomData_from_bmeshpoly is used correctly
Follow up to last commit, since bugs here aren't so obvious.
This commit is contained in:
parent
1e7a8ab5e8
commit
7fab7b63f9
Notes:
blender-bot
2023-02-14 08:41:36 +01:00
Referenced by issue #46056, User Preferences-> install from File freezes Blender Referenced by issue #46054, Instant crash with Shift+B in a viewport with active render border
|
@ -381,6 +381,10 @@ void CustomData_bmesh_update_active_layers(struct CustomData *fdata, struct Cust
|
|||
void CustomData_bmesh_do_versions_update_active_layers(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata);
|
||||
void CustomData_bmesh_init_pool(struct CustomData *data, int totelem, const char htype);
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *pdata, CustomData *ldata, bool fallback);
|
||||
#endif
|
||||
|
||||
/* External file storage */
|
||||
|
||||
void CustomData_external_add(struct CustomData *data,
|
||||
|
|
|
@ -601,6 +601,8 @@ void DM_generate_tangent_tessface_data(DerivedMesh *dm, bool generate)
|
|||
CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
|
||||
}
|
||||
|
||||
BLI_assert(CustomData_from_bmeshpoly_test(fdata, pdata, ldata, true));
|
||||
|
||||
loopindex = MEM_mallocN(sizeof(*loopindex) * totface, __func__);
|
||||
|
||||
for (mf_idx = 0, mf = mface; mf_idx < totface; mf_idx++, mf++) {
|
||||
|
|
|
@ -2489,6 +2489,10 @@ void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *l
|
|||
void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *ldata, int total)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* avoid accumulating extra layers */
|
||||
BLI_assert(!CustomData_from_bmeshpoly_test(fdata, pdata, ldata, false));
|
||||
|
||||
for (i = 0; i < pdata->totlayer; i++) {
|
||||
if (pdata->layers[i].type == CD_MTEXPOLY) {
|
||||
CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, pdata->layers[i].name);
|
||||
|
@ -2515,6 +2519,41 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
|
|||
CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
/**
|
||||
* Debug check, used to assert when we expect layers to be in/out of sync.
|
||||
*
|
||||
* \param fallback: Use when there are no layers to handle,
|
||||
* since callers may expect success or failure.
|
||||
*/
|
||||
bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *pdata, CustomData *ldata, bool fallback)
|
||||
{
|
||||
int a_num = 0, b_num = 0;
|
||||
#define LAYER_CMP(l_a, t_a, l_b, t_b) \
|
||||
((a_num += CustomData_number_of_layers(l_a, t_a)) == (b_num += CustomData_number_of_layers(l_b, t_b)))
|
||||
|
||||
if (!LAYER_CMP(pdata, CD_MTEXPOLY, fdata, CD_MTFACE))
|
||||
return false;
|
||||
if (!LAYER_CMP(ldata, CD_MLOOPCOL, fdata, CD_MCOL))
|
||||
return false;
|
||||
if (!LAYER_CMP(ldata, CD_PREVIEW_MLOOPCOL, fdata, CD_PREVIEW_MCOL))
|
||||
return false;
|
||||
if (!LAYER_CMP(ldata, CD_ORIGSPACE_MLOOP, fdata, CD_ORIGSPACE))
|
||||
return false;
|
||||
if (!LAYER_CMP(ldata, CD_NORMAL, fdata, CD_TESSLOOPNORMAL))
|
||||
return false;
|
||||
if (!LAYER_CMP(ldata, CD_TANGENT, fdata, CD_TANGENT))
|
||||
return false;
|
||||
|
||||
#undef TEST_RET
|
||||
|
||||
/* if no layers are on either CustomData's,
|
||||
* then there was nothing to do... */
|
||||
return a_num ? true : fallback;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void CustomData_bmesh_update_active_layers(CustomData *fdata, CustomData *pdata, CustomData *ldata)
|
||||
{
|
||||
int act;
|
||||
|
|
Loading…
Reference in New Issue