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
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 a4cd7eb..65931fb 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
@@ -356,6 +356,15 @@
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();
@@ -792,6 +801,15 @@
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);