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.
This commit is contained in:
Sergey Sharybin 2018-09-12 12:21:04 +02:00
parent f088bbae6a
commit aa844ad676
Notes: blender-bot 2023-02-14 11:20:29 +01:00
Referenced by issue #56798, Normals in Cycles contain NaN
Referenced by issue #56799, "Save Buffers" doesn't allow saving the volume passes
Referenced by issue #56773, Latest Blender/Cycles build will crash in GPU mode (Blue Screen with 4594cc25ac)
Referenced by issue #56775, Cycles - Render crashes Blender
Referenced by issue #56761, Crash - Principled Shader with Transmission greater than 0
1 changed files with 12 additions and 4 deletions

View File

@ -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;