Bug 570649 - [macOS][BigSur] NPE error when initialize GLCanvas object.
Summary: [macOS][BigSur] NPE error when initialize GLCanvas object.
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.18   Edit
Hardware: PC Mac OS X
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 575659 569361
  Show dependency tree
 
Reported: 2021-01-25 21:35 EST by Stella Ma CLA
Modified: 2022-07-07 15:59 EDT (History)
6 users (show)

See Also:


Attachments
Snippet that reproduces the bug (1.90 KB, text/plain)
2021-05-28 07:18 EDT, Mario Marinato CLA
no flags Details
Snippet to reproduce this bug. (759 bytes, application/octet-stream)
2022-03-18 09:34 EDT, Brian Hsu CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stella Ma CLA 2021-01-25 21:35:43 EST
Hi SWT team, 

Recently when I use SWT 4.18 on my macOS Bis Sur machine, I find that I will see a null pointer error when I initialize or use a GLCanvas object. The bug is easy to reproduce, just a line of `new GLCanvas(this, SWT.NONE, new GLData());` The error stack trace looks like below:

```
Unhandled exception in the UI thread.
java.lang.NullPointerException
 	at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:763)
 	at org.eclipse.swt.widgets.Canvas.drawRect(Canvas.java:170)
 	at org.eclipse.swt.widgets.Display.windowProc(Display.java:6037)
 	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
 	at org.eclipse.swt.widgets.Display.applicationNextEventMatchingMask(Display.java:5317)
 	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5710)
 	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
 	at org.eclipse.swt.internal.cocoa.NSApplication.nextEventMatchingMask(NSApplication.java:92)
 	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3833)
 	at org.eclipse.jface.window.Window.runEventLoop(Window.java:823)
 	at org.eclipse.jface.window.Window.open(Window.java:799)
 	at com.google.gapid.Main$UI.show(Main.java:136)
 	at com.google.gapid.Main.main(Main.java:80)
```

Would really appreciate your help and looking forward to your reply, thanks!!
Comment 1 Mario Marinato CLA 2021-05-25 12:34:25 EDT
I have a similar situation here, using Eclipse 4.19 (2021-03) on Big Sur.

The error pops up when I call Display.readAndDispatch() on my event loop:

while ( !myShell.isDisposed() ) {
  if ( !display.readAndDispatch() )
    display.sleep();
  }
}

This is the error I get. The stack is a bit different, but the NPE is at the same Widget.java:763 line.

java.lang.NullPointerException
  at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:763)
  at org.eclipse.swt.widgets.Canvas.drawRect(Canvas.java:170)
  at org.eclipse.swt.widgets.Display.windowProc(Display.java:6046)
  at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
  at org.eclipse.swt.widgets.Display.applicationNextEventMatchingMask(Display.java:5315)
  at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5719)
  at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
  at org.eclipse.swt.internal.cocoa.NSApplication.nextEventMatchingMask(NSApplication.java:92)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3831)
  at mjCanvas.MJCanvas.main(MJCanvas.java:57)

(I feel I must add that Big Sur is major nightmare. Lot's of problems on the RCP we develop.)
Comment 2 Alexis Drogoul CLA 2021-05-25 21:16:15 EDT
Same here. Using Eclipse 4.19, on Big Sur, together with JOGL (which creates its own canvas). 

The stack I systematically obtain is: 

Closing msi.gama.application.view.InteractiveConsoleView
java.lang.NullPointerException
	at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:763)
	at org.eclipse.swt.widgets.Canvas.drawRect(Canvas.java:170)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:6046)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationNextEventMatchingMask(Display.java:5315)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5719)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.nextEventMatchingMask(NSApplication.java:92)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3831)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
	at msi.gama.application.Application.start(Application.java:143)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1461)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1434)


So a bit different, of course, but it seems that SWT/macOS is unable to create a (or pass a valid) graphics context.
Comment 3 Lakshmi P Shanmugam CLA 2021-05-28 04:03:30 EDT
Can you please provide a snippet to reproduce the problem?
Comment 4 Mario Marinato CLA 2021-05-28 07:18:50 EDT
Created attachment 286470 [details]
Snippet that reproduces the bug

There you go, a snippet.

Comment / uncomment lines 33 and 36 to see the difference in behavior.

This same snippet can be used to reproduce Bug 573782.
Comment 5 Brian Hsu CLA 2022-03-18 09:34:17 EDT
Created attachment 288245 [details]
Snippet to reproduce this bug.

I could also reproduce this bug at MacOS Monterey (12.0.1) with lwjgl-3.3.1 binding.

The problem is caused by line 20:

    GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

If this line is removed, everything is fine.

Here is the stack trace:

[error] Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.internal.cocoa.NSGraphicsContext.saveGraphicsState()" because "context" is null
[error] 	at org.eclipse.swt.widgets.Widget.drawRect(Widget.java:764)
[error] 	at org.eclipse.swt.widgets.Canvas.drawRect(Canvas.java:170)
[error] 	at org.eclipse.swt.widgets.Display.windowProc(Display.java:6252)
[error] 	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
[error] 	at org.eclipse.swt.widgets.Display.applicationNextEventMatchingMask(Display.java:5530)
[error] 	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5930)
[error] 	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
[error] 	at org.eclipse.swt.internal.cocoa.NSApplication.nextEventMatchingMask(NSApplication.java:92)
[error] 	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3964)
[error] 	at example.Snippet1.main(Snippet1.java:27)
Comment 6 Laurent Marchal CLA 2022-07-07 15:59:14 EDT
This bug has affected our product for more than a year and makes it impossible to use any OpenGL on OSX. Is there anything we can to to help get it fixed ? It's very easy to reproduce but I'm not familiar with SWT development.
Thanks