Browse Source

[bug] fix size of data

Former-commit-id: df0d7ca4e2c13cf34c10b81d7aaf962205f62dbe
pancha 8 năm trước cách đây
mục cha
commit
a9ba6a1083
1 tập tin đã thay đổi với 2 bổ sung2 xóa
  1. 2 2
      include/igl/png/render_to_png.cpp

+ 2 - 2
include/igl/png/render_to_png.cpp

@@ -17,7 +17,7 @@ IGL_INLINE bool igl::png::render_to_png(
   const bool alpha,
   const bool fast)
 {
-  unsigned char * data = new unsigned char[width*height];
+  unsigned char * data = new unsigned char[4*width*height];
   glReadPixels(
     0,
     0,
@@ -35,7 +35,7 @@ IGL_INLINE bool igl::png::render_to_png(
       data[4*(i+j*width)+3] = 255;
     }
   }
-  bool ret = stbi_write_png(png_file.c_str(), width, height, 4, data, width*sizeof(unsigned char));
+  bool ret = stbi_write_png(png_file.c_str(), width, height, 4, data, 4*width*sizeof(unsigned char));
   delete [] data;
   return ret;
 }