Commit 229cd729 authored by Deni's avatar Deni Committed by Alexander Alekhin
Browse files

Merge pull request #2309 from deni64k:master

Fix memory corruption in RgbdPlane

* Fix memory corruption

* Use divUp instead of explicit rounding up integer division

* rgbd: add test
parent 8fde8d74
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -584,8 +584,8 @@ private:
        plane = Ptr<PlaneBase>(new PlaneABC(plane_grid.m_(y, x), n, (int)index_plane,
			(float)sensor_error_a_, (float)sensor_error_b_, (float)sensor_error_c_));

      Mat_<unsigned char> plane_mask = Mat_<unsigned char>::zeros(points3d.rows / block_size_,
                                                                          points3d.cols / block_size_);
      Mat_<unsigned char> plane_mask = Mat_<unsigned char>::zeros(divUp(points3d.rows, block_size_),
                                                                  divUp(points3d.cols, block_size_));
      std::set<TileQueue::PlaneTile> neighboring_tiles;
      neighboring_tiles.insert(front_tile);
      plane_queue.remove(front_tile.y_, front_tile.x_);
+11 −0
Original line number Diff line number Diff line
@@ -470,4 +470,15 @@ TEST(Rgbd_Plane, compute)
  test.safe_run();
}

TEST(Rgbd_Plane, regression_2309_valgrind_check)
{
    Mat points(640, 480, CV_32FC3, Scalar::all(0));
    rgbd::RgbdPlane plane_detector;
    plane_detector.setBlockSize(9);  // Note, 640%9 is 1 and 480%9 is 3

    Mat mask;
    std::vector<cv::Vec4f> planes;
    plane_detector(points, mask, planes);  // Will corrupt memory; valgrind gets triggered
}

}} // namespace