From a6aacd0647b8990f66de8f695ae6ea5a7590a551 Mon Sep 17 00:00:00 2001 From: Wolfgang Hess Date: Tue, 8 Nov 2016 16:14:35 +0100 Subject: [PATCH] Fix and add CHECKs when writing X-ray output. (#120) Before the allocation was too large which resulted in excessive memory consumption. Also adds CHECKs for the stride size and the success of the Cairo writer function. --- cartographer/io/xray_points_processor.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cartographer/io/xray_points_processor.cc b/cartographer/io/xray_points_processor.cc index 3834e63..005b4e1 100644 --- a/cartographer/io/xray_points_processor.cc +++ b/cartographer/io/xray_points_processor.cc @@ -49,7 +49,8 @@ void TakeLogarithm(Eigen::MatrixXf* mat) { void WritePng(const string& filename, const Eigen::MatrixXf& mat) { const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, mat.cols()); - std::vector pixels(stride * mat.rows(), 0.); + CHECK_EQ(stride % 4, 0); + std::vector pixels(stride / 4 * mat.rows(), 0.); const float max = mat.maxCoeff(); for (int y = 0; y < mat.rows(); ++y) { @@ -71,7 +72,9 @@ void WritePng(const string& filename, const Eigen::MatrixXf& mat) { reinterpret_cast(pixels.data()), CAIRO_FORMAT_ARGB32, mat.cols(), mat.rows(), stride), cairo_surface_destroy); - cairo_surface_write_to_png(surface.get(), filename.c_str()); + CHECK_EQ(cairo_surface_status(surface.get()), CAIRO_STATUS_SUCCESS); + CHECK_EQ(cairo_surface_write_to_png(surface.get(), filename.c_str()), + CAIRO_STATUS_SUCCESS); } } // namespace