From d077c7333faf8bf76c24cf6936653b6d13426c13 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 28 Oct 2018 14:51:14 +0100 Subject: [PATCH] fix crash in debug mode in sketcher in case the equation matrix has rank zero --- src/Mod/Sketcher/App/planegcs/GCS.cpp | 53 +++++++++++++++------------ 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/Mod/Sketcher/App/planegcs/GCS.cpp b/src/Mod/Sketcher/App/planegcs/GCS.cpp index dacd4fca9d..f6ad9f0c86 100644 --- a/src/Mod/Sketcher/App/planegcs/GCS.cpp +++ b/src/Mod/Sketcher/App/planegcs/GCS.cpp @@ -3803,29 +3803,36 @@ int System::diagnose(Algorithm alg) #ifdef EIGEN_SPARSEQR_COMPATIBLE else if(qrAlgorithm==EigenSparseQR){ if (SJ.rows() > 0) { - SqrJT.compute(SJ.topRows(jacobianconstraintcount).transpose()); - // Do not ask for Q Matrix!! - // At Eigen 3.2 still has a bug that this only works for square matrices - // if enabled it will crash - #ifdef SPARSE_Q_MATRIX - Q = SqrJT.matrixQ(); - //Q = QS; - #endif - - paramsNum = SqrJT.rows(); - constrNum = SqrJT.cols(); - SqrJT.setPivotThreshold(qrpivotThreshold); - rank = SqrJT.rank(); - - if (constrNum >= paramsNum) - R = SqrJT.matrixR().triangularView(); - else - R = SqrJT.matrixR().topRows(constrNum) - .triangularView(); - - #ifdef _GCS_DEBUG_SOLVER_JACOBIAN_QR_DECOMPOSITION_TRIANGULAR_MATRIX - R2 = SqrJT.matrixR(); - #endif + auto SJT = SJ.topRows(jacobianconstraintcount).transpose(); + if (SJT.rows() > 0 && SJT.cols() > 0) { + SqrJT.compute(SJT); + // Do not ask for Q Matrix!! + // At Eigen 3.2 still has a bug that this only works for square matrices + // if enabled it will crash + #ifdef SPARSE_Q_MATRIX + Q = SqrJT.matrixQ(); + //Q = QS; + #endif + + paramsNum = SqrJT.rows(); + constrNum = SqrJT.cols(); + SqrJT.setPivotThreshold(qrpivotThreshold); + rank = SqrJT.rank(); + + if (constrNum >= paramsNum) + R = SqrJT.matrixR().triangularView(); + else + R = SqrJT.matrixR().topRows(constrNum) + .triangularView(); + + #ifdef _GCS_DEBUG_SOLVER_JACOBIAN_QR_DECOMPOSITION_TRIANGULAR_MATRIX + R2 = SqrJT.matrixR(); + #endif + } + else { + paramsNum = SJT.rows(); + constrNum = SJT.cols(); + } } } #endif