From b6eb7dae59aa3150abba467b1f12517c5bac8246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles=20Fl=C3=A8che?= Date: Mon, 11 Apr 2022 14:22:13 +0200 Subject: Fix Cycles missing nullptr check in case mesh has no shader Did not affect Blender, but could happen with other integrations. Differential Revision: https://developer.blender.org/D14538 --- intern/cycles/scene/mesh.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'intern') diff --git a/intern/cycles/scene/mesh.cpp b/intern/cycles/scene/mesh.cpp index 05024a7790e..b5c0d9d92fb 100644 --- a/intern/cycles/scene/mesh.cpp +++ b/intern/cycles/scene/mesh.cpp @@ -690,12 +690,16 @@ void Mesh::pack_shaders(Scene *scene, uint *tri_shader) bool last_smooth = false; size_t triangles_size = num_triangles(); - int *shader_ptr = shader.data(); + const int *shader_ptr = shader.data(); + const bool *smooth_ptr = smooth.data(); for (size_t i = 0; i < triangles_size; i++) { - if (shader_ptr[i] != last_shader || last_smooth != smooth[i]) { - last_shader = shader_ptr[i]; - last_smooth = smooth[i]; + const int new_shader = shader_ptr ? shader_ptr[i] : INT_MAX; + const bool new_smooth = smooth_ptr ? smooth_ptr[i] : false; + + if (new_shader != last_shader || last_smooth != new_smooth) { + last_shader = new_shader; + last_smooth = new_smooth; Shader *shader = (last_shader < used_shaders.size()) ? static_cast(used_shaders[last_shader]) : scene->default_surface; -- cgit v1.2.3