mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
slightly more clear memory handling for async tasks
This commit is contained in:
parent
f8d7dc2f06
commit
2cd3bd4ff4
@ -312,7 +312,7 @@ public:
|
|||||||
Matrix *matrix):
|
Matrix *matrix):
|
||||||
Nan::AsyncWorker(callback),
|
Nan::AsyncWorker(callback),
|
||||||
bg(bg),
|
bg(bg),
|
||||||
matrix(matrix) {
|
matrix(new Matrix::Matrix(matrix)) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +398,7 @@ NAN_METHOD(BackgroundSubtractorWrap::Apply) {
|
|||||||
|
|
||||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||||
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
|
||||||
Nan::AsyncQueueWorker(new AsyncBackgroundSubtractorWorker( callback, self, new Matrix::Matrix(_img)));
|
Nan::AsyncQueueWorker(new AsyncBackgroundSubtractorWorker( callback, self, _img));
|
||||||
return;
|
return;
|
||||||
} else { //synchronous - return the image
|
} else { //synchronous - return the image
|
||||||
|
|
||||||
|
|||||||
@ -809,7 +809,7 @@ public:
|
|||||||
AsyncToBufferWorker(Nan::Callback *callback, Matrix *matrix, std::string ext,
|
AsyncToBufferWorker(Nan::Callback *callback, Matrix *matrix, std::string ext,
|
||||||
std::vector<int> params) :
|
std::vector<int> params) :
|
||||||
Nan::AsyncWorker(callback),
|
Nan::AsyncWorker(callback),
|
||||||
matrix(matrix), // dulipcate mat, adding ref, but not copying data
|
matrix(new Matrix(matrix)), // dulipcate matrix, adding ref, but not copying data
|
||||||
ext(ext),
|
ext(ext),
|
||||||
params(params) {
|
params(params) {
|
||||||
}
|
}
|
||||||
@ -894,7 +894,7 @@ NAN_METHOD(Matrix::ToBufferAsync) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||||
Nan::AsyncQueueWorker(new AsyncToBufferWorker(callback, new Matrix(self), ext, params));
|
Nan::AsyncQueueWorker(new AsyncToBufferWorker(callback, self, ext, params));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1089,7 +1089,7 @@ class AsyncSaveWorker: public Nan::AsyncWorker {
|
|||||||
public:
|
public:
|
||||||
AsyncSaveWorker(Nan::Callback *callback, Matrix *matrix, char* filename) :
|
AsyncSaveWorker(Nan::Callback *callback, Matrix *matrix, char* filename) :
|
||||||
Nan::AsyncWorker(callback),
|
Nan::AsyncWorker(callback),
|
||||||
matrix(matrix),
|
matrix(new Matrix(matrix)),
|
||||||
filename(filename) {
|
filename(filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1143,7 +1143,7 @@ NAN_METHOD(Matrix::SaveAsync) {
|
|||||||
REQ_FUN_ARG(1, cb);
|
REQ_FUN_ARG(1, cb);
|
||||||
|
|
||||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||||
Nan::AsyncQueueWorker(new AsyncSaveWorker(callback, new Matrix(self), *filename));
|
Nan::AsyncQueueWorker(new AsyncSaveWorker(callback, self, *filename));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1942,7 +1942,7 @@ class ResizeASyncWorker: public Nan::AsyncWorker {
|
|||||||
public:
|
public:
|
||||||
ResizeASyncWorker(Nan::Callback *callback, Matrix *image, cv::Size size, double fx, double fy, int interpolation) :
|
ResizeASyncWorker(Nan::Callback *callback, Matrix *image, cv::Size size, double fx, double fy, int interpolation) :
|
||||||
Nan::AsyncWorker(callback),
|
Nan::AsyncWorker(callback),
|
||||||
image(image),
|
image(new Matrix(image)),
|
||||||
dest(cv::Mat()),
|
dest(cv::Mat()),
|
||||||
size(size),
|
size(size),
|
||||||
fx(fx),
|
fx(fx),
|
||||||
@ -1968,12 +1968,13 @@ public:
|
|||||||
|
|
||||||
void HandleOKCallback() {
|
void HandleOKCallback() {
|
||||||
Nan::HandleScope scope;
|
Nan::HandleScope scope;
|
||||||
|
|
||||||
|
delete image;
|
||||||
|
image = NULL;
|
||||||
|
|
||||||
if (success){
|
if (success){
|
||||||
try{
|
try{
|
||||||
Local<Object> im_to_return = Matrix::CreateWrappedFromMat(dest);
|
Local<Object> im_to_return = Matrix::CreateWrappedFromMat(dest);
|
||||||
delete image;
|
|
||||||
image = NULL;
|
|
||||||
dest.release(); //release our refcount before handing it back to the callback
|
dest.release(); //release our refcount before handing it back to the callback
|
||||||
|
|
||||||
Local<Value> argv[] = {
|
Local<Value> argv[] = {
|
||||||
@ -2079,7 +2080,7 @@ NAN_METHOD(Matrix::Resize) {
|
|||||||
if (isAsync){
|
if (isAsync){
|
||||||
REQ_FUN_ARG(numargs-1, cb);
|
REQ_FUN_ARG(numargs-1, cb);
|
||||||
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
|
||||||
Nan::AsyncQueueWorker(new ResizeASyncWorker(callback, new Matrix(self), size, fx, fy, interpolation));
|
Nan::AsyncQueueWorker(new ResizeASyncWorker(callback, self, size, fx, fy, interpolation));
|
||||||
info.GetReturnValue().Set(Nan::Null());
|
info.GetReturnValue().Set(Nan::Null());
|
||||||
} else {
|
} else {
|
||||||
try{
|
try{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user