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

Bug 508129

Summary: [Cocoa][10.11] PaintEvent.GC.copyArea () crashes Eclipse Neon on OSX 10.11 and above
Product: [Eclipse Project] Platform Reporter: saikarthik Natesan <saikarthik.kn>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: arunkumar.thondapu, lshanmug, peter
Version: 4.6   
Target Milestone: 4.8 M2   
Hardware: Macintosh   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/103273
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=f28f8cb0510c91905751bee0f128e0912d8324c8
Whiteboard:
Bug Depends on:    
Bug Blocks: 516837    

Description saikarthik Natesan CLA 2016-11-24 10:18:25 EST
On OSX 10.11 (and also in 10.12) after upgrading to Eclipse Neon, our application crashes.  Our application gets GC from PaintEvent and every gc from paintEvent crashes in GC.copyArea(Image image, int x, int y),  This doesn’t  crash for if GC is created.  I guess that scenario got fixed as part of bug 480852. The sample mentioned in bug 480852 works well in Neon. But if I add a canvas and use the gc from PaintListener, it crashes. Please note that the crash happens only in Neon and works well in Luna and Mars. 
 
The following same code/sample works well in Luna & Mars on OSX 10.11. This crashes only on Neon

	Display display = new Display();
	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	Canvas canvas = new Canvas(shell, SWT.NONE);
	canvas.addPaintListener(new PaintListener() {
	 @Override
	  public void paintControl(PaintEvent e) {
	   Shell placeholder = new Shell(((Canvas) e.widget).getShell(), SWT.NO_TRIM);
           Button btn = new Button(placeholder, SWT.CHECK);
	   btn.setSelection(false);
	   Point bsize = btn.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	   btn.setSize(bsize);
	   placeholder.setSize(bsize);
	   btn.setLocation(0, 0);
	   placeholder.open();
           //GC gc = new GC(btn);
	   final Image image = new Image(((Canvas) e.widget).getDisplay(), bsize.x, bsize.y);
	   e.gc.copyArea(image, 0, 0); // Crashing
	   //gc.x(image, 0, 0);
	   placeholder.close();
	  }
	 });
	shell.open();
	while (!shell.isDisposed()) {
	 if (!display.readAndDispatch()) {
	  display.sleep();
	 }
	}
	display.dispose();
Comment 1 Lakshmi P Shanmugam CLA 2017-05-18 06:50:16 EDT
On 10.12, I get a hang, not a crash. The problem here is that there is recursion causing the hang.
e.gc.copyArea(image, 0, 0) causes the Canvas to send a paint event and calls the e.gc.copyArea() in the Listener code again & again.
This can be verified if we remove the listener in the listener code by adding canvas.removeListener(this) before calling e.gc.copyArea().
I think GC.copyArea() is not expected to send a paint event. Will need to investigate this further.
Comment 2 Eclipse Genie CLA 2017-08-18 03:07:30 EDT
New Gerrit change created: https://git.eclipse.org/r/103273
Comment 4 Lakshmi P Shanmugam CLA 2017-08-18 08:19:33 EDT
Pushed the fix to master, will verify with the next I-build.
Comment 5 Lakshmi P Shanmugam CLA 2017-08-22 01:21:41 EDT
Verified fix in I20170821-2000.
Comment 6 Lakshmi P Shanmugam CLA 2017-09-12 15:12:22 EDT
Verified with I20170911-2000.