summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXDraw.c
diff options
context:
space:
mode:
authorculler <culler>2018-11-07 21:17:25 (GMT)
committerculler <culler>2018-11-07 21:17:25 (GMT)
commit6a78e0b7fc7c69f35442f490812e5265db8e8470 (patch)
tree86af0c57abcf76c8e38e1e180055bed0a93187e8 /macosx/tkMacOSXDraw.c
parent52bdce0ef2fe1a7ad9884d739ccab438740b4db1 (diff)
downloadtk-6a78e0b7fc7c69f35442f490812e5265db8e8470.zip
tk-6a78e0b7fc7c69f35442f490812e5265db8e8470.tar.gz
tk-6a78e0b7fc7c69f35442f490812e5265db8e8470.tar.bz2
Fix two image bugs. BitmapImageReps may have bytesPerRow > 4*width. Do not copy
from a window to a bitmap if the contentView does not have a valid graphics context.
Diffstat (limited to 'macosx/tkMacOSXDraw.c')
-rw-r--r--macosx/tkMacOSXDraw.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index 42c9059..bff2f93 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -155,16 +155,32 @@ TkMacOSXBitmapRepFromDrawableRect(
CGImageRelease(cg_image);
}
} else if ( (view = TkMacOSXDrawableView(mac_drawable)) ) {
+
/*
* Convert Tk top-left to NSView bottom-left coordinates.
*/
+
int view_height = [view bounds].size.height;
NSRect view_rect = NSMakeRect(x + mac_drawable->xOff,
view_height - height - y - mac_drawable->yOff,
width, height);
- bitmap_rep = [view bitmapImageRepForCachingDisplayInRect: view_rect];
- [bitmap_rep retain];
- [view cacheDisplayInRect:view_rect toBitmapImageRep:bitmap_rep];
+
+ /*
+ * Attempt to copy from the view to a bitmapImageRep. If the view does
+ * not have a valid CGContext, doing this will silently corrupt memory
+ * and make a big mess. So, in that case, we mark the view as needing
+ * display and return NULL.
+ */
+
+ if (view == [NSView focusView]) {
+ bitmap_rep = [view bitmapImageRepForCachingDisplayInRect: view_rect];
+ [bitmap_rep retain];
+ [view cacheDisplayInRect:view_rect toBitmapImageRep:bitmap_rep];
+ } else {
+ TkMacOSXDbgMsg("No CGContext - cannot copy from screen to bitmap.");
+ [view setNeedsDisplay:YES];
+ return NULL;
+ }
} else {
TkMacOSXDbgMsg("Invalid source drawable");
}