From ab0bd505d2a667dcb22e3b64fb936bda434bfb7e Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Fri, 10 Nov 2017 09:49:12 +0000 Subject: [PATCH] resize(async): seems we can get an assert in Unwrap if image has 0,0, size, so catch and report as a callback error. --- src/Matrix.cc | 57 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/src/Matrix.cc b/src/Matrix.cc index 962230a..9a5839d 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -1919,22 +1919,35 @@ public: Nan::HandleScope scope; if (success){ - Local im_to_return= Nan::NewInstance(Nan::GetFunction(Nan::New(Matrix::constructor)).ToLocalChecked()).ToLocalChecked(); - Matrix *img = Nan::ObjectWrap::Unwrap(im_to_return); - img->mat = dest->mat; - delete dest; - - //delete dest; - - Local argv[] = { - Nan::Null(), // err - im_to_return //result - }; + try{ + Local im_to_return= Nan::NewInstance(Nan::GetFunction(Nan::New(Matrix::constructor)).ToLocalChecked()).ToLocalChecked(); + Matrix *img = Nan::ObjectWrap::Unwrap(im_to_return); + img->mat = dest->mat; + delete dest; - Nan::TryCatch try_catch; - callback->Call(2, argv); - if (try_catch.HasCaught()) { - Nan::FatalException(try_catch); + //delete dest; + + Local argv[] = { + Nan::Null(), // err + im_to_return //result + }; + + Nan::TryCatch try_catch; + callback->Call(2, argv); + if (try_catch.HasCaught()) { + Nan::FatalException(try_catch); + } + } catch (...){ + Local argv[] = { + Nan::New("C++ exception wrapping response").ToLocalChecked(), // err + Nan::Null() // result + }; + + Nan::TryCatch try_catch; + callback->Call(2, argv); + if (try_catch.HasCaught()) { + Nan::FatalException(try_catch); + } } } else { delete dest; @@ -2022,11 +2035,15 @@ NAN_METHOD(Matrix::Resize) { Nan::AsyncQueueWorker(new ResizeASyncWorker(callback, self, size, fx, fy, interpolation)); info.GetReturnValue().Set(Nan::Null()); } else { - Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); - cv::Mat res = cv::Mat(x, y, CV_32FC3); - cv::resize(self->mat, res, cv::Size(x, y), 0, 0, interpolation); - ~self->mat; - self->mat = res; + try{ + Matrix *self = Nan::ObjectWrap::Unwrap(info.This()); + cv::Mat res = cv::Mat(x, y, CV_32FC3); + cv::resize(self->mat, res, cv::Size(x, y), 0, 0, interpolation); + ~self->mat; + self->mat = res; + } catch (...){ + return Nan::ThrowError("c++ Exception processing resize"); + } } }