diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-09-12 13:21:04 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-09-12 13:28:55 +0300 |
commit | aa844ad676d2e9d4f72f773fde64712c8a794e5e (patch) | |
tree | cb0d6b71b07c4ecc3d22674a74daa19d642b50fc /intern/cycles | |
parent | f088bbae6af2224b49103d8cba5129f92796ffa6 (diff) |
Cycles: Don't allocate Extra if BSDF allocation failed
Failed as in did not allocate due to possibly weight cutoff.
Tryign to allocated Extra storage for closure in such situation
will consfuse Cycles and cause crashes later one due to obscure
values in ShaderData.
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/svm/svm_closure.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h index df879de1950..64bf8244999 100644 --- a/intern/cycles/kernel/svm/svm_closure.h +++ b/intern/cycles/kernel/svm/svm_closure.h @@ -258,7 +258,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * float3 spec_weight = weight * specular_weight; MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), spec_weight); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + MicrofacetExtra *extra = (bsdf != NULL) + ? (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)) + : NULL; if (bsdf && extra) { bsdf->N = N; @@ -308,7 +310,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * #endif { MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight*fresnel); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + MicrofacetExtra *extra = (bsdf != NULL) + ? (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)) + : NULL; if (bsdf && extra) { bsdf->N = N; @@ -355,7 +359,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * } else { /* use multi-scatter GGX */ MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + MicrofacetExtra *extra = (bsdf != NULL) + ? (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)) + : NULL; if(bsdf && extra) { bsdf->N = N; @@ -385,7 +391,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * #endif if(clearcoat > CLOSURE_WEIGHT_CUTOFF) { MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight); - MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)); + MicrofacetExtra *extra = (bsdf != NULL) + ? (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra)) + : NULL; if(bsdf && extra) { bsdf->N = clearcoat_normal; |