From acbc7362dbe60fcadbfc5584166e47721d6e5466 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 1 Apr 2014 18:00:44 -0700 Subject: [PATCH] Bug #3611 Initializing static cv::Mat with cv::Mat::zeros causes segmentation fault fixed. fix MatOpInitializer --- modules/core/src/matop.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/core/src/matop.cpp b/modules/core/src/matop.cpp index 243c821..c3717ca 100644 --- a/modules/core/src/matop.cpp +++ b/modules/core/src/matop.cpp @@ -203,7 +203,11 @@ public: static void makeExpr(MatExpr& res, int method, int ndims, const int* sizes, int type, double alpha=1); }; -static MatOp_Initializer g_MatOp_Initializer; +static MatOp_Initializer* getGlobalMatOpInitializer() +{ + static MatOp_Initializer initializer; + return &initializer; +} static inline bool isIdentity(const MatExpr& e) { return e.op == &g_MatOp_Identity; } static inline bool isAddEx(const MatExpr& e) { return e.op == &g_MatOp_AddEx; } @@ -216,7 +220,7 @@ static inline bool isInv(const MatExpr& e) { return e.op == &g_MatOp_Invert; } static inline bool isSolve(const MatExpr& e) { return e.op == &g_MatOp_Solve; } static inline bool isGEMM(const MatExpr& e) { return e.op == &g_MatOp_GEMM; } static inline bool isMatProd(const MatExpr& e) { return e.op == &g_MatOp_GEMM && (!e.c.data || e.beta == 0); } -static inline bool isInitializer(const MatExpr& e) { return e.op == &g_MatOp_Initializer; } +static inline bool isInitializer(const MatExpr& e) { return e.op == getGlobalMatOpInitializer(); } ///////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1580,12 +1584,12 @@ void MatOp_Initializer::multiply(const MatExpr& e, double s, MatExpr& res) const inline void MatOp_Initializer::makeExpr(MatExpr& res, int method, Size sz, int type, double alpha) { - res = MatExpr(&g_MatOp_Initializer, method, Mat(sz, type, (void*)0), Mat(), Mat(), alpha, 0); + res = MatExpr(getGlobalMatOpInitializer(), method, Mat(sz, type, (void*)0), Mat(), Mat(), alpha, 0); } inline void MatOp_Initializer::makeExpr(MatExpr& res, int method, int ndims, const int* sizes, int type, double alpha) { - res = MatExpr(&g_MatOp_Initializer, method, Mat(ndims, sizes, type, (void*)0), Mat(), Mat(), alpha, 0); + res = MatExpr(getGlobalMatOpInitializer(), method, Mat(ndims, sizes, type, (void*)0), Mat(), Mat(), alpha, 0); } /////////////////////////////////////////////////////////////////////////////////////////////////////////// -- 2.7.4