From 166fb11a3a477476eb3efc7ae687e477b662d110 Mon Sep 17 00:00:00 2001 From: Simon Hofmann Date: Mon, 22 Mar 2021 10:57:15 +0100 Subject: [PATCH 1/2] (#47) Deleted src/buffer_finalizer.h --- src/buffer_finalizer.h | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/buffer_finalizer.h diff --git a/src/buffer_finalizer.h b/src/buffer_finalizer.h deleted file mode 100644 index 396d164..0000000 --- a/src/buffer_finalizer.h +++ /dev/null @@ -1,14 +0,0 @@ -template -class BufferFinalizer -{ -public: - void operator()(Napi::Env env, T *data) - { - (void)env; - if (data != nullptr) - { - delete data; - } - } -}; - From 938e3dee945ca8196ebfd336a685f2aa08e361ce Mon Sep 17 00:00:00 2001 From: Simon Hofmann Date: Mon, 22 Mar 2021 10:57:50 +0100 Subject: [PATCH 2/2] (#47) Switched to using Buffer::Copy --- src/main.cc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main.cc b/src/main.cc index cec6da7..9e21292 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,5 @@ #include -#include "buffer_finalizer.h" #include "keypress.h" #include "microsleep.h" #include "MMBitmap.h" @@ -11,7 +10,6 @@ int mouseDelay = 10; int keyboardDelay = 10; -static BufferFinalizer finalizer; /* __ __ @@ -243,12 +241,6 @@ Napi::Number _scrollMouse(const Napi::CallbackInfo &info) return Napi::Number::New(env, 1); } -Napi::Number _theAnswer(const Napi::CallbackInfo &info) { - Napi::Env env = info.Env(); - - return Napi::Number::New(env, 42); -} - /* _ __ _ _ | |/ /___ _ _| |__ ___ __ _ _ __ __| | @@ -763,8 +755,8 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info) throw Napi::Error::New(env, "Error: Failed to capture screen"); } - uint32_t bufferSize = (uint32_t)(bitmap->bytewidth * bitmap->height); - Napi::Buffer buffer = Napi::Buffer::New(env, (char *)bitmap->imageBuffer, bufferSize, finalizer); + uint64_t bufferSize = bitmap->bytewidth * bitmap->height; + Napi::Buffer buffer = Napi::Buffer::Copy(env, (char *)bitmap->imageBuffer, bufferSize); Napi::Object obj = Napi::Object::New(env); obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, (double)bitmap->width)); @@ -774,12 +766,12 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info) obj.Set(Napi::String::New(env, "bytesPerPixel"), Napi::Number::New(env, bitmap->bytesPerPixel)); obj.Set(Napi::String::New(env, "image"), buffer); + destroyMMBitmap(bitmap); + return obj; } Napi::Object Init(Napi::Env env, Napi::Object exports) { - exports.Set(Napi::String::New(env, "theAnswer"), Napi::Function::New(env, _theAnswer)); - exports.Set(Napi::String::New(env, "dragMouse"), Napi::Function::New(env, _dragMouse)); exports.Set(Napi::String::New(env, "moveMouse"), Napi::Function::New(env, _moveMouse)); exports.Set(Napi::String::New(env, "getMousePos"), Napi::Function::New(env, _getMousePos));