void rst::rasterizer::set_pixel(const Eigen::Vector3f& point, const Eigen::Vector3f& color)
{
//old index: auto ind = point.y() + point.x() * width;
if (point.x() < 0 || point.x() >= width ||
point.y() < 0 || point.y() >= height) return;
auto ind = (height-point.y())*width + point.x();
// if out of range, return
if (ind >= width * height) return;
frame_buf[ind] = color;
}
闪退是因为在set_pixel计算ind的时候,超出屏幕外的三角形边上的点对应的ind会大于或者等于width * weight,而frame_buf的大小为width * weight,所以会发生数组访问越界错误,加上这个判断即可
This post has received 2 votes up.