diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-08 23:58:17 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-09 22:28:00 +0300 |
commit | 21a535840df1887245b90376a0de427f2a848806 (patch) | |
tree | be7619efd57294371387ec64e99e81b4988b7a85 /intern/cycles/kernel/osl | |
parent | 1ffa01b6f874403cb1b30f9f1ecd52088501f436 (diff) |
Fix T53270: crash with multiscatter GGX after recent refactoring.
In fact this was an existing issue when exceeding the number of available
closure, but it's more common now that we set the number to 0 for shadows
and emission
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r-- | intern/cycles/kernel/osl/osl_closures.cpp | 102 |
1 files changed, 60 insertions, 42 deletions
diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp index 68c707e6c3e..e3e85705ebc 100644 --- a/intern/cycles/kernel/osl/osl_closures.cpp +++ b/intern/cycles/kernel/osl/osl_closures.cpp @@ -186,22 +186,22 @@ public: MicrofacetBsdf *alloc(ShaderData *sd, int path_flag, float3 weight) { MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc_osl(sd, sizeof(MicrofacetBsdf), weight, ¶ms); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); - if(bsdf && extra) { - bsdf->extra = extra; - - bsdf->ior = 1.5f; - - bsdf->alpha_x = clearcoat_roughness; - bsdf->alpha_y = clearcoat_roughness; - - bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f); - bsdf->extra->clearcoat = clearcoat; + if(!bsdf) { + return NULL; + } - return bsdf; + MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + if(!extra) { + return NULL; } - return NULL; + bsdf->extra = extra; + bsdf->ior = 1.5f; + bsdf->alpha_x = clearcoat_roughness; + bsdf->alpha_y = clearcoat_roughness; + bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f); + bsdf->extra->clearcoat = clearcoat; + return bsdf; } void setup(ShaderData *sd, int path_flag, float3 weight) @@ -359,18 +359,24 @@ public: /* Technically, the MultiGGX Glass closure may also transmit. However, * since this is set statically and only used for caustic flags, this * is probably as good as it gets. */ - if(!skip(sd, path_flag, LABEL_GLOSSY | LABEL_REFLECT)) { - MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc_osl(sd, sizeof(MicrofacetBsdf), weight, ¶ms); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); - if(bsdf && extra) { - bsdf->extra = extra; - bsdf->extra->color = color; - bsdf->extra->cspec0 = cspec0; - return bsdf; - } + if(skip(sd, path_flag, LABEL_GLOSSY | LABEL_REFLECT)) { + return NULL; + } + + MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc_osl(sd, sizeof(MicrofacetBsdf), weight, ¶ms); + if(!bsdf) { + return NULL; + } + + MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + if(!extra) { + return NULL; } - return NULL; + bsdf->extra = extra; + bsdf->extra->color = color; + bsdf->extra->cspec0 = cspec0; + return bsdf; } }; @@ -437,17 +443,23 @@ public: /* Technically, the MultiGGX closure may also transmit. However, * since this is set statically and only used for caustic flags, this * is probably as good as it gets. */ - if(!skip(sd, path_flag, LABEL_GLOSSY|LABEL_REFLECT)) { - MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc_osl(sd, sizeof(MicrofacetBsdf), weight, ¶ms); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); - if(bsdf && extra) { - bsdf->extra = extra; - bsdf->extra->color = color; - return bsdf; - } + if(skip(sd, path_flag, LABEL_GLOSSY|LABEL_REFLECT)) { + return NULL; } - return NULL; + MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc_osl(sd, sizeof(MicrofacetBsdf), weight, ¶ms); + if(!bsdf) { + return NULL; + } + + MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + if(!extra) { + return NULL; + } + + bsdf->extra = extra; + bsdf->extra->color = color; + return bsdf; } }; @@ -536,18 +548,24 @@ public: /* Technically, the MultiGGX closure may also transmit. However, * since this is set statically and only used for caustic flags, this * is probably as good as it gets. */ - if(!skip(sd, path_flag, LABEL_GLOSSY | LABEL_REFLECT)) { - MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc_osl(sd, sizeof(MicrofacetBsdf), weight, ¶ms); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); - if(bsdf && extra) { - bsdf->extra = extra; - bsdf->extra->color = color; - bsdf->extra->cspec0 = cspec0; - return bsdf; - } + if(skip(sd, path_flag, LABEL_GLOSSY | LABEL_REFLECT)) { + return NULL; + } + + MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc_osl(sd, sizeof(MicrofacetBsdf), weight, ¶ms); + if(!bsdf) { + return NULL; + } + + MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + if(!extra) { + return NULL; } - return NULL; + bsdf->extra = extra; + bsdf->extra->color = color; + bsdf->extra->cspec0 = cspec0; + return bsdf; } }; |