Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369757

Summary: [3.7.x] GLCanvas maintenance fix causes NullPointerException when changing parent on Mac
Product: [Eclipse Project] Platform Reporter: Steven Darnell <darnells>
Component: SWTAssignee: Silenio Quarti <Silenio_Quarti>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: gheorghe, remy.suen, Silenio_Quarti
Version: 4.2Flags: john.arthorne: pmc_approved+
gheorghe: review+
Target Milestone: 3.7.2   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Modified code snippet to reproduce bug (contains JOGL dependency) none

Description Steven Darnell CLA 2012-01-25 18:15:44 EST
Build Identifier: M20120118-0800

I use GLCanvas in my RCP app and a common workflow is to change the parent window of the widget (often moving a CTabFolder containing the GLCanvas from one partition to another). The app uses Eclipse SDK 3.7.0 and the correct behavior is observed. The workflow causes a NullPointerException when using a recent 3.7.x stream build (e.g. M20120118-0800).

I confirmed that you can successfully change the parent of a GLCanvas in SWT 3.7.0 and 3.7.1. The (soon to be) attached code snippet can be used to reproduce the error by changing the sample project's SWT dependency. I only tested the 32-bit version of SWT; I assume the same holds true for the 64-bit version.

I suspect this defect was introduced with the fix to Bug 343331, which was last changed 9/7/2011 (change previous to that in 2009).

I marked this bug CRITICAL as it introduces a crash condition in a maintenance release. I expect the same fix will be required in the 4.2/3.8 branch.

Reproducible: Always

Steps to Reproduce:
1. Create two shells (shell1, shell2)
2. Create a GLCanvas and set shell1 as parent
3. Change GLCanvas parent to shell2

Exception in thread "main" java.lang.NullPointerException
	at org.eclipse.swt.widgets.Canvas.viewWillMoveToWindow(Canvas.java:614)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5683)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSView.addSubview(NSView.java:36)
	at org.eclipse.swt.widgets.Control.setParent(Control.java:3942)
	at steve.opengl.GLCanvasParentSwap.main(GLCanvasParentSwap.java:139)
Comment 1 Steven Darnell CLA 2012-01-25 18:24:06 EST
Created attachment 210089 [details]
Modified code snippet to reproduce bug (contains JOGL dependency)

Snippet creates two shells and a GLCanvas, the changes the parent of the canvas from the first to the second shell. Comment in code indicates what triggers the exception.
Comment 2 Steven Darnell CLA 2012-01-25 18:31:21 EST
@Silenio
I am CC'ing you because you were instrumental to the GLCanvas fast view fix on Mac (Bug 343331). I apologize if this is out of line.
Comment 4 Silenio Quarti CLA 2012-01-26 10:56:02 EST
John/Bogdan, please could approve/review this patch for 3.7.2?

This is a regression in 3.7.2, it must be fixed.

The NullPointer happens because during the callback #viewWillMoveToWindow, NSView.window() returns null.  The fix is to use the window stored in the shell of the GLCanvas.