Fix T45729: Cycles Bake break when building a special mesh
The issue was caused by CD_SHAPEKEY_INDEX layer being added to edge data, now we make sure all the layers are nicely re-allocated.
This commit is contained in:
parent
540f9a3b11
commit
c6d7562896
Notes:
blender-bot
2023-02-14 10:04:50 +01:00
Referenced by issue #45729, Cycles Bake break when building a special mesh
|
@ -131,6 +131,14 @@ void CustomData_update_typemap(struct CustomData *data);
|
|||
bool CustomData_merge(const struct CustomData *source, struct CustomData *dest,
|
||||
CustomDataMask mask, int alloctype, int totelem);
|
||||
|
||||
/* Reallocate custom data to a new element count.
|
||||
* Only affects on data layers which are owned by the CustomData itself,
|
||||
* referenced data is kept unchanged,
|
||||
*
|
||||
* NOTE: Take care of referenced layers by yourself!
|
||||
*/
|
||||
void CustomData_realloc(struct CustomData *data, int totelem);
|
||||
|
||||
/* bmesh version of CustomData_merge; merges the layouts of source and dest,
|
||||
* then goes through the mesh and makes sure all the customdata blocks are
|
||||
* consistent with the new layout.*/
|
||||
|
|
|
@ -1504,6 +1504,23 @@ bool CustomData_merge(const struct CustomData *source, struct CustomData *dest,
|
|||
return changed;
|
||||
}
|
||||
|
||||
/* NOTE: Take care of referenced layers by yourself! */
|
||||
void CustomData_realloc(CustomData *data, int totelem)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < data->totlayer; ++i) {
|
||||
CustomDataLayer *layer = &data->layers[i];
|
||||
const LayerTypeInfo *typeInfo;
|
||||
int size;
|
||||
if (layer->flag & CD_FLAG_NOFREE) {
|
||||
continue;
|
||||
}
|
||||
typeInfo = layerType_getInfo(layer->type);
|
||||
size = totelem * typeInfo->size;
|
||||
layer->data = MEM_reallocN(layer->data, size);
|
||||
}
|
||||
}
|
||||
|
||||
void CustomData_copy(const struct CustomData *source, struct CustomData *dest,
|
||||
CustomDataMask mask, int alloctype, int totelem)
|
||||
{
|
||||
|
|
|
@ -2237,7 +2237,7 @@ void BKE_mesh_split_faces(Mesh *mesh)
|
|||
BKE_mesh_calc_normals_split(mesh);
|
||||
}
|
||||
lnors = CustomData_get_layer(&mesh->ldata, CD_NORMAL);
|
||||
/* Count. */
|
||||
/* Count number of vertices to be split. */
|
||||
for (poly = 0; poly < num_polys; poly++) {
|
||||
MPoly *mp = &mpoly[poly];
|
||||
int loop;
|
||||
|
@ -2255,19 +2255,16 @@ void BKE_mesh_split_faces(Mesh *mesh)
|
|||
/* No new vertices are to be added, can do early exit. */
|
||||
return;
|
||||
}
|
||||
/* Actual split. */
|
||||
/* Reallocate all vert and edge related data. */
|
||||
mesh->totvert += num_new_verts;
|
||||
mesh->totedge += 2 * num_new_verts;
|
||||
mvert = mesh->mvert = MEM_reallocN(mesh->mvert,
|
||||
sizeof(MVert) * mesh->totvert);
|
||||
medge = mesh->medge = MEM_reallocN(mesh->medge,
|
||||
sizeof(MEdge) * mesh->totedge);
|
||||
if (mesh->dvert != NULL) {
|
||||
mesh->dvert = MEM_reallocN(mesh->dvert, sizeof(MDeformVert) * mesh->totvert);
|
||||
CustomData_set_layer(&mesh->vdata, CD_MDEFORMVERT, mesh->dvert);
|
||||
}
|
||||
CustomData_set_layer(&mesh->vdata, CD_MVERT, mesh->mvert);
|
||||
CustomData_set_layer(&mesh->edata, CD_MEDGE, mesh->medge);
|
||||
CustomData_realloc(&mesh->vdata, mesh->totvert);
|
||||
CustomData_realloc(&mesh->edata, mesh->totedge);
|
||||
/* Update pointers to a newly allocated memory. */
|
||||
BKE_mesh_update_customdata_pointers(mesh, false);
|
||||
mvert = mesh->mvert;
|
||||
medge = mesh->medge;
|
||||
/* Perform actual vertex split. */
|
||||
num_new_verts = 0;
|
||||
for (poly = 0; poly < num_polys; poly++) {
|
||||
MPoly *mp = &mpoly[poly];
|
||||
|
|
Loading…
Reference in New Issue