Skip to content

Commit 938ac42

Browse files
authored
Merge pull request #54 from lewisl9029/handle-null-screenshot-bitmap
Throw error on null bitmap to prevent crash
2 parents dda0761 + ae6c27d commit 938ac42

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/main.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,10 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
758758
}
759759

760760
MMBitmapRef bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, w, h));
761+
762+
if (bitmap == NULL) {
763+
throw Napi::Error::New(env, "Error: Failed to capture screen");
764+
}
761765

762766
uint32_t bufferSize = bitmap->bytewidth * bitmap->height;
763767
Napi::Buffer<char> buffer = Napi::Buffer<char>::New(env, (char *)bitmap->imageBuffer, bufferSize, finalizer);

0 commit comments

Comments
 (0)