From 68de483bf3c7d2fc3e9c5ba5d62dd4303fba7bf4 Mon Sep 17 00:00:00 2001 From: Weizhen Huang Date: Mon, 13 May 2024 19:02:02 +0200 Subject: [PATCH] Fix: Ray Portal BSDF changing `sd->flag` when closure is not allocated when ray exceeds `max_bounce`, we do not allocate any closure at intersection. However, Ray Portal BSDF still added `SD_BSDF` flag, resulting in undefined behavior in `integrate_surface_bsdf_bssrdf_bounce()`. This part of code was similar to Transparent BSDF, however, Transparent closure was still allocated in this case. To fix the undefined behavior, add `SD_BSDF` flag only when the Ray Portal closure was allocated. --- intern/cycles/kernel/closure/bsdf_ray_portal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intern/cycles/kernel/closure/bsdf_ray_portal.h b/intern/cycles/kernel/closure/bsdf_ray_portal.h index 39edb6d459d..7f724e054db 100644 --- a/intern/cycles/kernel/closure/bsdf_ray_portal.h +++ b/intern/cycles/kernel/closure/bsdf_ray_portal.h @@ -28,12 +28,12 @@ ccl_device void bsdf_ray_portal_setup(ccl_private ShaderData *sd, } sd->closure_transparent_extinction += weight; - sd->flag |= SD_BSDF | SD_RAY_PORTAL; ccl_private RayPortalClosure *pc = (ccl_private RayPortalClosure *)closure_alloc( sd, sizeof(RayPortalClosure), CLOSURE_BSDF_RAY_PORTAL_ID, weight); if (pc) { + sd->flag |= SD_BSDF | SD_RAY_PORTAL; if (is_zero(direction)) { direction = -sd->wi; }