Skip to content

Commit

Permalink
Don't apply invalid colors in VBORenderer. Fixes openscad#5216 (opens…
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel authored Oct 1, 2024
1 parent 99a93c4 commit 202844c
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/glview/VBORenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ void VBORenderer::create_surface(const PolySet& ps, VertexArray& vertex_array,
for (int i = 0, n = ps.indices.size(); i < n; i++) {
const auto& poly = ps.indices[i];
const auto color_index = has_colors && i < ps.color_indices.size() ? ps.color_indices[i] : -1;
const auto& color = !force_default_color && color_index >= 0 && color_index < ps.colors.size() ? ps.colors[color_index] : default_color;
const auto& color =
!force_default_color &&
color_index >= 0 &&
color_index < ps.colors.size() &&
ps.colors[color_index].isValid() ?
ps.colors[color_index] : default_color;
if (poly.size() == 3) {
Vector3d p0 = uniqueMultiply(vert_mult_map, ps.vertices[poly.at(0)], m);
Vector3d p1 = uniqueMultiply(vert_mult_map, ps.vertices[poly.at(1)], m);
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ list(APPEND SCADFILES_WITH_COLOR
${EXAMPLES_DIR}/Basics/rotate_extrude.scad
${EXAMPLES_DIR}/Old/example017.scad

${TEST_SCAD_DIR}/3D/issues/issue5216.scad
${TEST_SCAD_DIR}/3D/issues/issue5217.scad

#${TEST_SCAD_DIR}/bugs/issue1000.scad
Expand Down
1 change: 1 addition & 0 deletions tests/data/scad/3D/issues/issue5216.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
color() cube();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 202844c

Please sign in to comment.