From 4eee9f1f63fa81e64c15e0659231475a0c2d6ce7 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 22 Jan 2014 20:39:21 +0000 Subject: Mac OS: handle possible NULL return after screen capture attempt. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10078 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_cocoa.mm | 2 ++ src/fl_read_image_mac.cxx | 1 + src/fl_scroll_area.cxx | 12 +++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 814604f22..14ea72303 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -3351,6 +3351,7 @@ unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w */ { NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h); + if (bitmap == nil) return NULL; *bytesPerPixel = [bitmap bitsPerPixel]/8; int bpp = (int)[bitmap bytesPerPlane]; int bpr = (int)[bitmap bytesPerRow]; @@ -3388,6 +3389,7 @@ CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, i else { int bpp; unsigned char *bitmap = bitmap_from_window_rect(win, x, y, w, h, &bpp); + if (!bitmap) return NULL; CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB(); CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, w*h*bpp, imgProviderReleaseData); img = CGImageCreate(w, h, 8, 8*bpp, w*bpp, lut, diff --git a/src/fl_read_image_mac.cxx b/src/fl_read_image_mac.cxx index 5dbd70781..a92684d1a 100644 --- a/src/fl_read_image_mac.cxx +++ b/src/fl_read_image_mac.cxx @@ -45,6 +45,7 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate Fl_Window *window = Fl_Window::current(); while(window->window()) window = window->window(); base = Fl_X::bitmap_from_window_rect(window,x,y,w,h,&delta); + if (!base) return NULL; rowBytes = delta*w; x = y = 0; } diff --git a/src/fl_scroll_area.cxx b/src/fl_scroll_area.cxx index 7531f3d90..a8cba57c4 100644 --- a/src/fl_scroll_area.cxx +++ b/src/fl_scroll_area.cxx @@ -143,11 +143,13 @@ void fl_scroll(int X, int Y, int W, int H, int dx, int dy, #elif defined(__APPLE_QUARTZ__) CGImageRef img = Fl_X::CGImage_from_window_rect(Fl_Window::current(), src_x, src_y, src_w, src_h); - CGRect rect = { { dest_x, dest_y }, { src_w, src_h } }; - Fl_X::q_begin_image(rect, 0, 0, src_w, src_h); - CGContextDrawImage(fl_gc, rect, img); - Fl_X::q_end_image(); - CFRelease(img); + if (img) { + CGRect rect = { { dest_x, dest_y }, { src_w, src_h } }; + Fl_X::q_begin_image(rect, 0, 0, src_w, src_h); + CGContextDrawImage(fl_gc, rect, img); + Fl_X::q_end_image(); + CFRelease(img); + } #else # error unsupported platform #endif -- cgit v1.2.3