From c2e0a8afb2fa58daa9577374304bcb7959f5112b Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Thu, 22 Feb 2024 14:50:26 +0100 Subject: [PATCH] Use null matrix for invalid transport result --- Matrix.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Matrix.h b/Matrix.h index c8ed8ca..b9b9d18 100644 --- a/Matrix.h +++ b/Matrix.h @@ -28,9 +28,17 @@ public: // but the data size should be equal to avoid problems // We cannot check the data size directly, but the row*col should be equal unsigned int matrixSize = this->cols * this->rows; - if (matrixSize != r->rows * r->cols) - // Exception??? For now we don't do anything + unsigned int resultSize = r->rows * r->cols; + if (matrixSize != resultSize) { + // Return a null matrix; + // We dont set data to nullptr because it is allocated memory + // Instead we write all zeros + for (int dataIx = 0; dataIx < resultSize; dataIx++) + r->data[dataIx] = 0.0f; + r->rows = 0; + r->cols = 0; return; + } r->cols = this->rows; r->rows = this->cols;