EEVEE: Fix crash when using animated visibility with motion blur steps

This was caused by the same VBO being remapped twice by
`EEVEE_motion_blur_cache_finish`. Leading to memory corruption.
This commit is contained in:
Clément Foucault
2021-01-30 16:35:52 +01:00
parent 5d215d5225
commit 3a954af862

View File

@@ -457,9 +457,6 @@ void EEVEE_motion_blur_cache_finish(EEVEE_Data *vedata)
}
else {
GPUVertBuf *vbo = mb_geom->vbo[mb_step];
/* If this assert fails, it means that different EEVEE_GeometryMotionDatas
* has been used for each motion blur step. */
BLI_assert(vbo);
if (vbo) {
/* Use the vbo to perform the copy on the GPU. */
GPU_vertbuf_use(vbo);
@@ -470,6 +467,10 @@ void EEVEE_motion_blur_cache_finish(EEVEE_Data *vedata)
int attrib_id = GPU_vertformat_attr_id_get(format, "pos");
GPU_vertformat_attr_rename(format, attrib_id, (mb_step == MB_PREV) ? "prv" : "nxt");
}
else {
/* This might happen if the object visibility has been animated. */
mb_geom->use_deform = false;
}
}
break;
@@ -515,6 +516,8 @@ void EEVEE_motion_blur_swap_data(EEVEE_Data *vedata)
DRW_TEXTURE_FREE_SAFE(mb_hair->psys[i].hair_pos_tx[MB_PREV]);
mb_hair->psys[i].hair_pos[MB_PREV] = mb_hair->psys[i].hair_pos[MB_NEXT];
mb_hair->psys[i].hair_pos_tx[MB_PREV] = mb_hair->psys[i].hair_pos_tx[MB_NEXT];
mb_hair->psys[i].hair_pos[MB_NEXT] = NULL;
mb_hair->psys[i].hair_pos_tx[MB_NEXT] = NULL;
}
break;
@@ -529,9 +532,10 @@ void EEVEE_motion_blur_swap_data(EEVEE_Data *vedata)
}
GPU_VERTBUF_DISCARD_SAFE(mb_geom->vbo[MB_PREV]);
mb_geom->vbo[MB_PREV] = mb_geom->vbo[MB_NEXT];
mb_geom->vbo[MB_NEXT] = NULL;
if (mb_geom->vbo[MB_NEXT]) {
GPUVertBuf *vbo = mb_geom->vbo[MB_NEXT];
if (mb_geom->vbo[MB_PREV]) {
GPUVertBuf *vbo = mb_geom->vbo[MB_PREV];
GPUVertFormat *format = (GPUVertFormat *)GPU_vertbuf_get_format(vbo);
int attrib_id = GPU_vertformat_attr_id_get(format, "nxt");
GPU_vertformat_attr_rename(format, attrib_id, "prv");