diff options
author | Bastien Montagne <bastien@blender.org> | 2020-10-02 12:42:36 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2020-10-02 12:47:35 +0300 |
commit | 2b90dd1ac581881c0cf0d784692a26bcfd4f494e (patch) | |
tree | 19e25e074d85247cdc32f608279705f49c08e721 /source/blender | |
parent | 062dfab159d3c8e27635c0cd91b15d6736eb61b7 (diff) |
Fix (unreported) assert in texture code when loading some old 2.74 blend file.
Trying to open the 2.74 Fishy Cat file would generate endless asserts in
customdata code. This commit refactors and cleans up the code of
`psys_get_dupli_texture` to avoid useless calls and data access, and
validate data before trying to further access it.
No behavioral changes expected here (besides getting rid of the assert).
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/particle.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 1ac46f4f17f..f265eade749 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -4804,7 +4804,6 @@ void psys_get_dupli_texture(ParticleSystem *psys, float orco[3]) { MFace *mface; - MTFace *mtface; float loc[3]; int num; @@ -4816,21 +4815,25 @@ void psys_get_dupli_texture(ParticleSystem *psys, * For now just include this workaround as an alternative to crashing, * but longer term meta-balls should behave in a more manageable way, see: T46622. */ - uv[0] = uv[1] = 0.f; + uv[0] = uv[1] = 0.0f; /* Grid distribution doesn't support UV or emit from vertex mode */ bool is_grid = (part->distr == PART_DISTR_GRID && part->from != PART_FROM_VERT); if (cpa) { if ((part->childtype == PART_CHILD_FACES) && (psmd->mesh_final != NULL)) { - CustomData *mtf_data = &psmd->mesh_final->fdata; - const int uv_idx = CustomData_get_render_layer(mtf_data, CD_MTFACE); - mtface = CustomData_get_layer_n(mtf_data, CD_MTFACE, uv_idx); - - if (mtface && !is_grid) { - mface = CustomData_get(&psmd->mesh_final->fdata, cpa->num, CD_MFACE); - mtface += cpa->num; - psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv); + if (!is_grid) { + CustomData *mtf_data = &psmd->mesh_final->fdata; + const int uv_idx = CustomData_get_render_layer(mtf_data, CD_MTFACE); + + if (uv_idx >= 0) { + MTFace *mtface = CustomData_get_layer_n(mtf_data, CD_MTFACE, uv_idx); + if (mtface != NULL) { + mface = CustomData_get(&psmd->mesh_final->fdata, cpa->num, CD_MFACE); + mtface += cpa->num; + psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv); + } + } } psys_particle_on_emitter(psmd, @@ -4851,10 +4854,6 @@ void psys_get_dupli_texture(ParticleSystem *psys, } if ((part->from == PART_FROM_FACE) && (psmd->mesh_final != NULL) && !is_grid) { - CustomData *mtf_data = &psmd->mesh_final->fdata; - const int uv_idx = CustomData_get_render_layer(mtf_data, CD_MTFACE); - mtface = CustomData_get_layer_n(mtf_data, CD_MTFACE, uv_idx); - num = pa->num_dmcache; if (num == DMCACHE_NOTFOUND) { @@ -4867,10 +4866,16 @@ void psys_get_dupli_texture(ParticleSystem *psys, num = DMCACHE_NOTFOUND; } - if (mtface && !ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) { - mface = CustomData_get(&psmd->mesh_final->fdata, num, CD_MFACE); - mtface += num; - psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv); + if (!ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) { + CustomData *mtf_data = &psmd->mesh_final->fdata; + const int uv_idx = CustomData_get_render_layer(mtf_data, CD_MTFACE); + + if (uv_idx >= 0) { + MTFace *mtface = CustomData_get_layer_n(mtf_data, CD_MTFACE, uv_idx); + mface = CustomData_get(&psmd->mesh_final->fdata, num, CD_MFACE); + mtface += num; + psys_interpolate_uvs(mtface, mface->v4, pa->fuv, uv); + } } } |