diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-08-24 15:30:54 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-08-24 18:54:25 +0300 |
commit | dc74d60915e550d3e8b3665afc5435a1d752614b (patch) | |
tree | 4a5a21771fa3405cef4b3097b7e68fc54a153da5 /intern/cycles/kernel | |
parent | 9498eb269253284846c98c8d0d1be6e3e0ae9c2f (diff) |
Fix T79819: crash with OSL trace() and getmessage() after Embree changes
The return value of scene_intersect must be checked, the isect struct members
can't be assumed to be initialized if that returns false.
Differential Revision: https://developer.blender.org/D8692
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r-- | intern/cycles/kernel/osl/osl_globals.h | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.cpp | 8 |
2 files changed, 6 insertions, 3 deletions
diff --git a/intern/cycles/kernel/osl/osl_globals.h b/intern/cycles/kernel/osl/osl_globals.h index c06c9abd4c1..caca3c28c8d 100644 --- a/intern/cycles/kernel/osl/osl_globals.h +++ b/intern/cycles/kernel/osl/osl_globals.h @@ -90,6 +90,7 @@ struct OSLTraceData { ShaderData sd; bool setup; bool init; + bool hit; }; /* thread key for thread specific data lookup */ diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index 5292b5f8055..aee1e3a244e 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -1481,6 +1481,7 @@ bool OSLRenderServices::trace(TraceOpt &options, tracedata->ray = ray; tracedata->setup = false; tracedata->init = true; + tracedata->hit = false; tracedata->sd.osl_globals = sd->osl_globals; KernelGlobals *kg = sd->osl_globals; @@ -1492,7 +1493,8 @@ bool OSLRenderServices::trace(TraceOpt &options, /* Raytrace, leaving out shadow opaque to avoid early exit. */ uint visibility = PATH_RAY_ALL_VISIBILITY - PATH_RAY_SHADOW_OPAQUE; - return scene_intersect(kg, &ray, visibility, &tracedata->isect); + tracedata->hit = scene_intersect(kg, &ray, visibility, &tracedata->isect); + return tracedata->hit; } bool OSLRenderServices::getmessage(OSL::ShaderGlobals *sg, @@ -1506,9 +1508,9 @@ bool OSLRenderServices::getmessage(OSL::ShaderGlobals *sg, if (source == u_trace && tracedata->init) { if (name == u_hit) { - return set_attribute_int((tracedata->isect.prim != PRIM_NONE), type, derivatives, val); + return set_attribute_int(tracedata->hit, type, derivatives, val); } - else if (tracedata->isect.prim != PRIM_NONE) { + else if (tracedata->hit) { if (name == u_hitdist) { float f[3] = {tracedata->isect.t, 0.0f, 0.0f}; return set_attribute_float(f, type, derivatives, val); |