Fix T53978: Bad memory access after recent fix to BSDF mixing

Added proper checks after BSDF allocation and cleaned up existing
inline checks.

Was introduced in 7261d675e6
This commit is contained in:
Mai Lavelle 2018-02-01 19:59:22 -05:00
parent 78a77fe622
commit b2dc0e6970
Notes: blender-bot 2024-04-29 13:07:32 +02:00
Referenced by issue #53978, Cycles Displacement node makes Blender prone to crash
1 changed files with 50 additions and 10 deletions

View File

@ -208,7 +208,11 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
sd->flag |= (bsdf) ? bsdf_microfacet_ggx_clearcoat_setup(bsdf, sd) : 0;
if(!bsdf) {
return;
}
sd->flag |= bsdf_microfacet_ggx_clearcoat_setup(bsdf, sd);
}
};
@ -391,9 +395,13 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if(!bsdf) {
return;
}
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
bsdf->alpha_y = bsdf->alpha_x;
sd->flag |= (bsdf) ? bsdf_microfacet_ggx_fresnel_setup(bsdf, sd) : 0;
sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
}
};
@ -417,7 +425,11 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
sd->flag |= (bsdf) ? bsdf_microfacet_ggx_aniso_fresnel_setup(bsdf, sd) : 0;
if(!bsdf) {
return;
}
sd->flag |= bsdf_microfacet_ggx_aniso_fresnel_setup(bsdf, sd);
}
};
@ -478,10 +490,14 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if(!bsdf) {
return;
}
bsdf->ior = 0.0f;
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
bsdf->alpha_y = bsdf->alpha_x;
sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_setup(bsdf) : 0;
sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
}
};
@ -503,8 +519,12 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if(!bsdf) {
return;
}
bsdf->ior = 0.0f;
sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_aniso_setup(bsdf) : 0;
sd->flag |= bsdf_microfacet_multi_ggx_aniso_setup(bsdf);
}
};
@ -530,9 +550,13 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if(!bsdf) {
return;
}
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
bsdf->alpha_y = bsdf->alpha_x;
sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_setup(bsdf) : 0;
sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(bsdf);
}
};
@ -591,9 +615,13 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if(!bsdf) {
return;
}
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
bsdf->alpha_y = bsdf->alpha_x;
sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd) : 0;
sd->flag |= bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd);
}
};
@ -617,7 +645,11 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_aniso_fresnel_setup(bsdf, sd) : 0;
if(!bsdf) {
return;
}
sd->flag |= bsdf_microfacet_multi_ggx_aniso_fresnel_setup(bsdf, sd);
}
};
@ -645,9 +677,13 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
if(!bsdf) {
return;
}
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
bsdf->alpha_y = bsdf->alpha_x;
sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd) : 0;
sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
}
};
@ -720,7 +756,11 @@ public:
volume_extinction_setup(sd, weight);
HenyeyGreensteinVolume *volume = (HenyeyGreensteinVolume*)bsdf_alloc_osl(sd, sizeof(HenyeyGreensteinVolume), weight, &params);
sd->flag |= (volume) ? volume_henyey_greenstein_setup(volume) : 0;
if(!volume) {
return;
}
sd->flag |= volume_henyey_greenstein_setup(volume);
}
};