Skip to content

Commit e1f97c5

Browse files
committed
Add safety value when surface tex has null data
1 parent f015d68 commit e1f97c5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/common/texture.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class image_texture : public texture {
7474
image_texture(unsigned char *pixels, int A, int B) : data(pixels), nx(A), ny(B) {}
7575

7676
virtual vec3 value(double u, double v, const vec3& p) const {
77+
// If we have no texture data, then always emit cyan (as a debugging aid).
78+
if (data == nullptr)
79+
return vec3(0,1,1);
80+
7781
auto i = static_cast<int>(( u)*nx);
7882
auto j = static_cast<int>((1-v)*ny-0.001);
7983

@@ -85,6 +89,7 @@ class image_texture : public texture {
8589
auto r = static_cast<int>(data[3*i + 3*nx*j+0]) / 255.0;
8690
auto g = static_cast<int>(data[3*i + 3*nx*j+1]) / 255.0;
8791
auto b = static_cast<int>(data[3*i + 3*nx*j+2]) / 255.0;
92+
8893
return vec3(r, g, b);
8994
}
9095

0 commit comments

Comments
 (0)