Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshmi Shanmugam2019-12-13 10:40:40 +0000
committerLakshmi P Shanmugam2021-05-18 09:44:14 +0000
commit68bf10cae6bd26a980b8108c25a64ac01d356bef (patch)
tree284341720bc79f933dfc832c7671cac7519eb5a7
parent30413b8028c38e4a25d3a56636b21514fd39ed5f (diff)
downloadeclipse.platform.swt-68bf10cae6bd26a980b8108c25a64ac01d356bef.tar.gz
eclipse.platform.swt-68bf10cae6bd26a980b8108c25a64ac01d356bef.tar.xz
eclipse.platform.swt-68bf10cae6bd26a980b8108c25a64ac01d356bef.zip
Bug 558214 - [Cocoa] NPE in drawRectangles
NSWindow.grahicsContext() has been deprecated since 10.14 and returns null. Try to create a graphics context from a new ImageRep. Change-Id: Ia96229bff2db0bdd3424ea276c5201b117a2a05e (cherry picked from commit c7ca9232da80053f1bf78c9f610574643ed39c12) Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/179635 Tested-by: Lakshmi P Shanmugam <lshanmug@in.ibm.com> Reviewed-by: Lakshmi P Shanmugam <lshanmug@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java
index 60a0303583..c113e86afc 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tracker.java
@@ -353,6 +353,15 @@ Rectangle [] computeProportions (Rectangle [] rects) {
void drawRectangles (NSWindow window, Rectangle [] rects, boolean erase) {
NSGraphicsContext context = window.graphicsContext();
+ if (context == null) {
+ long width = (long) window.frame().width;
+ long height = (long) window.frame().height;
+ NSBitmapImageRep rep = (NSBitmapImageRep) new NSBitmapImageRep().alloc();
+ rep = rep.initWithBitmapDataPlanes(0, width, height, 8, 3, false, false, OS.NSDeviceRGBColorSpace,
+ OS.NSAlphaFirstBitmapFormat, width * 4, 32);
+ context = NSGraphicsContext.graphicsContextWithBitmapImageRep(rep);
+ rep.release();
+ }
NSGraphicsContext.static_saveGraphicsState();
NSGraphicsContext.setCurrentContext(context);
context.saveGraphicsState();
@@ -789,6 +798,15 @@ public boolean open () {
window.setContentView(null);
window.setBackgroundColor(NSColor.clearColor());
NSGraphicsContext context = window.graphicsContext();
+ if (context == null) {
+ long width = (long) window.frame().width;
+ long height = (long) window.frame().height;
+ NSBitmapImageRep rep = (NSBitmapImageRep) new NSBitmapImageRep().alloc();
+ rep = rep.initWithBitmapDataPlanes(0, width, height, 8, 3, false, false, OS.NSDeviceRGBColorSpace,
+ OS.NSAlphaFirstBitmapFormat, width * 4, 32);
+ context = NSGraphicsContext.graphicsContextWithBitmapImageRep(rep);
+ rep.release();
+ }
NSGraphicsContext.static_saveGraphicsState();
NSGraphicsContext.setCurrentContext(context);
context.setCompositingOperation(OS.NSCompositeClear);

Back to the top