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

Bug 502711

Summary: [Cocoa][10.12] crashes on „macOS Sierra“ related to NSCopyBits
Product: [Eclipse Project] Platform Reporter: Till Brychcy <register.eclipse>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: apkdh78, arunkumar.thondapu, avsudhalkar, cdtdoug, daniel_megert, David.Hunka, horacio.vico, jaywettlaufer, jstevenson, julien.dehaudt, lshanmug, peter, prateek.goyal5, sanket.gadiya, vtherli
Version: 4.7   
Target Milestone: 4.7 M7   
Hardware: PC   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/82216
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=528fcab722ccdaa43c8d596494e2f2799889db3c
https://git.eclipse.org/r/93811
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=089958ed011ab767098213b25c7d079103bdee49
Whiteboard:
Bug Depends on: 502090    
Bug Blocks: 516704    
Attachments:
Description Flags
modified Snippet 240
none
modified Snippet240
none
modified Snippet240
none
Neon crash log none

Description Till Brychcy CLA 2016-09-29 16:51:38 EDT
Since the upgrade on macsOS sierra, I have started to observe crashes when deleting many lines in an editor or when switching the bottom tabs in a tabbed editor - luckily only in an eclipse started from another eclipse.

I can reproduce it on my machine with the m2e pom editor:
- Start eclipse from with eclipse with m2e installed
- Create a new maven project
- open the pom.xml
- click on „Effective POM“
- click on pom.xml
- click on „Effective POM“ again
- boom.

The hs_err_pid19939.log shows the crash is in NSCopyBits invoked from scroll:
C  [libsystem_platform.dylib+0x5f80]  _platform_memmove$VARIANT$Haswell+0xe0
C  [CoreGraphics+0xac760]  CGBlt_copyBytes+0x174
C  [CoreGraphics+0x18856]  argb32_image+0x13d6
C  [CoreGraphics+0x3e2169]  ripl_Mark+0x17
C  [CoreGraphics+0x3de286]  RIPLayerBltImage+0x40f
C  [CoreGraphics+0x81792]  ripc_RenderImage+0xe4
C  [CoreGraphics+0x82f12]  ripc_DrawImage+0x3eb
C  [CoreGraphics+0xfa28e]  CGContextDelegateDrawImage+0x30
C  [AppKit+0x1f56e8]  __backing_store_DrawImage_block_invoke+0x46
C  [AppKit+0x1f1027]  backing_store_delegate+0x3d8
C  [AppKit+0x1f5660]  backing_store_DrawImage+0x1f7
C  [CoreGraphics+0xfa28e]  CGContextDelegateDrawImage+0x30
C  [AppKit+0x4cc4be]  backing_store_DrawWindowContents+0x47e
C  [CoreGraphics+0xfa440]  CGContextDelegateDrawWindowContents+0x42
C  [SkyLight+0x189082]  SLContextCopyWindowContentsToRect+0x79
C  [AppKit+0x3e7629]  _NSRenderImageFromWindow+0x658
C  [AppKit+0x3e6fb1]  _NXScroll+0x1f3
C  [AppKit+0x8a1a95]  NSCopyBitsFromGraphicsContext+0x138
C  [AppKit+0x8a1957]  NSCopyBits+0x3a
C  [libswt-pi-cocoa-4713.jnilib+0xbdb0]  Java_org_eclipse_swt_internal_cocoa_OS_NSCopyBits+0x120
j  org.eclipse.swt.internal.cocoa.OS.NSCopyBits(JLorg/eclipse/swt/internal/cocoa/NSRect;Lorg/eclipse/swt/internal/cocoa/NSPoint;)V+0
j  org.eclipse.swt.widgets.Canvas.scroll(IIIIIIZ)V+351
j  org.eclipse.swt.custom.StyledText.scroll(IIIIIIZ)V+11
[…]

NSCopyBits is actually deprecated:
https://developer.apple.com/reference/appkit/1473630-nscopybits

A possible replacement (at least for the scrolling situation) is NSView scrollRect:by:
https://developer.apple.com/reference/appkit/nsview/1483497-scrollrect?language=objc

If I replace NSCopyBits with this, the crash goes away.

I’ll upload a patch via Gerrit.
It is obviously experimental, because it contains a hand-made binding for NSView scrollRect:by:
(There is already Bug 502090 with a request for updated binding, i’ve added a comment to that)

(There is another occurrence of NSCopyBits in org.eclipse.swt.graphics.GC.copyArea(int, int, int, int, int, int, boolean).
I haven’t checked if that can be replaced by scrollRect:by:, too)
Comment 1 Eclipse Genie CLA 2016-09-29 16:57:01 EDT
New Gerrit change created: https://git.eclipse.org/r/82216
Comment 2 John Stevenson CLA 2016-11-23 09:21:27 EST
We have a customer who is running into this in our product.  In this case they are not launching Eclipse from Eclipse.  They are just using our Eclipse based environment.

From the crash log it looks like the same problem

31  com.apple.AppKit                  0x00007fffb2aed629 _NSRenderImageFromWindow + 1624
32  com.apple.AppKit                  0x00007fffb2aecfb1 _NXScroll + 499
33  com.apple.AppKit                  0x00007fffb2fa7a95 NSCopyBitsFromGraphicsContext + 312
34  com.apple.AppKit                  0x00007fffb2fa7957 NSCopyBits + 58
35  libswt-pi-cocoa-4623.jnilib       0x000000012985d139 Java_org_eclipse_swt_internal_cocoa_OS_NSCopyBits + 187
Comment 3 Till Brychcy CLA 2017-03-08 07:42:12 EST
I'm setting 4.7M7 as target in the hopes that someone from the SWT team will find time to look at this...
Comment 4 Lakshmi P Shanmugam CLA 2017-03-23 07:25:27 EDT
Created attachment 267422 [details]
modified Snippet 240

I can reproduce the crash in Canvas.scroll with Snippet 48. 
I'm unable to reproduce a crash in GC.copyArea with the attached snippet. However, I think we should replace both the occurrences of NSCopyBits. I'll update the gerrit patch.
Comment 5 Lakshmi P Shanmugam CLA 2017-03-23 07:47:32 EDT
Created attachment 267424 [details]
modified Snippet240

Attached the modified Snippet240
Comment 7 Lakshmi P Shanmugam CLA 2017-03-23 08:16:00 EDT
Created attachment 267426 [details]
modified Snippet240

attached modified Snippet240
Comment 8 Lakshmi P Shanmugam CLA 2017-03-23 08:17:20 EDT
Thanks Till, for the bug report and the initial patch!
Comment 9 Eclipse Genie CLA 2017-03-24 10:09:06 EDT
New Gerrit change created: https://git.eclipse.org/r/93811
Comment 11 Lakshmi P Shanmugam CLA 2017-05-09 07:36:23 EDT
Verified in I20170508-2000
Comment 12 Till Brychcy CLA 2017-10-11 12:08:49 EDT
*** Bug 525879 has been marked as a duplicate of this bug. ***
Comment 13 AMIT SUDHALKAR CLA 2017-10-11 14:40:41 EDT
I was able to reproduce a similar issue in Eclipse Oxygen. When I select multiple lines and hit "delete"key it crashes eclipse:

Stack:

Stack: [0x00007ffeef400000,0x00007ffeefc00000],  sp=0x00007ffeefbf60b0,  free space=8152k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libsystem_platform.dylib+0x5091]  _platform_memmove$VARIANT$Haswell+0x171
C  [CoreGraphics+0x29795]  CGBlt_copyBytes+0x165
C  [CoreGraphics+0x2add7]  argb32_image+0x1387
C  [CoreGraphics+0x3924e1]  ripl_Mark+0x16
C  [CoreGraphics+0x38e8f9]  RIPLayerBltImage+0x40b
C  [CoreGraphics+0xfa803]  ripc_RenderImage+0xe4
C  [CoreGraphics+0xfbe1e]  ripc_DrawImage+0x34f
C  [CoreGraphics+0x65a30]  CGContextDelegateDrawImage+0x29
C  [AppKit+0x1d616f]  __backing_store_DrawImage_block_invoke+0x46
C  [AppKit+0x1d24a1]  backing_store_delegate+0x3c2
C  [AppKit+0x4cc666]  backing_store_DrawImage.llvm.20A1ED98+0x202
C  [CoreGraphics+0x65a30]  CGContextDelegateDrawImage+0x29
C  [AppKit+0x4cd500]  backing_store_DrawWindowContents.llvm.20A1ED98+0x4ad
C  [CoreGraphics+0x6ef0c]  CGContextDelegateDrawWindowContents+0x3b
C  [SkyLight+0x1cf0d8]  SLContextCopyWindowContentsToRect+0xb2
C  [AppKit+0x3ad97b]  _NSRenderImageFromWindow+0x5ae
C  [AppKit+0x3ad3ad]  _NXScroll+0x1c3
C  [AppKit+0x95a506]  NSCopyBitsFromGraphicsContext+0x138
C  [AppKit+0x95a3c8]  NSCopyBits+0x3a
C  [libswt-pi-cocoa-4711.jnilib+0xbdb0]  Java_org_eclipse_swt_internal_cocoa_OS_NSCopyBits+0x120
j  org.eclipse.swt.internal.cocoa.OS.NSCopyBits(JLorg/eclipse/swt/internal/cocoa/NSRect;Lorg/eclipse/swt/internal/cocoa/NSPoint;)V+0
j  org.eclipse.swt.widgets.Canvas.scroll(IIIIIIZ)V+326
j  org.eclipse.swt.custom.StyledText.scroll(IIIIIIZ)V+11
j  org.eclipse.swt.custom.StyledText.scrollText(II)V+75
j  org.eclipse.swt.custom.StyledText.handleTextChanging(Lorg/eclipse/swt/custom/TextChangingEvent;)V+180
j  org.eclipse.swt.custom.StyledText$5.textChanging(Lorg/eclipse/swt/custom/TextChangingEvent;)V+5
j  org.eclipse.jface.text.DefaultDocumentAdapter.fireTextChanging()V+195
j  org.eclipse.jface.text.DefaultDocumentAdapter.documentAboutToBeChanged(Lorg/eclipse/jface/text/DocumentEvent;)V+50
j  org.eclipse.jface.text.AbstractDocument.fireDocumentAboutToBeChanged(Lorg/eclipse/jface/text/DocumentEvent;)V+121
Comment 14 Till Brychcy CLA 2017-10-11 15:08:42 EDT
(In reply to AMIT SUDHALKAR from comment #13)
> I was able to reproduce a similar issue in Eclipse Oxygen. When I select
> multiple lines and hit "delete"key it crashes eclipse:
> 
[...]
> Stack:
[...]
> C  [libswt-pi-cocoa-4711.jnilib+0xbdb0]

This line shows that you are using an milestone build of Oxygen, Eclipse4.7M2.app

This bug was fixed in 4.7M7
Comment 15 AMIT SUDHALKAR CLA 2017-10-11 22:25:26 EDT
I downloaded the latest one available on the download site, where do I get the one with the fix, or is there a way to back port the fix to this version ?

Appreciate your help.
Comment 16 AMIT SUDHALKAR CLA 2017-10-11 22:25:41 EDT
I downloaded the latest one available on the download site, where do I get the one with the fix, or is there a way to back port the fix to this version ?

Appreciate your help.
Comment 17 AMIT SUDHALKAR CLA 2017-10-11 22:27:27 EDT
Is this the link to download the M7 version:

https://www.eclipse.org/downloads/packages/release/Oxygen/M7


(In reply to Till Brychcy from comment #14)
> (In reply to AMIT SUDHALKAR from comment #13)
> > I was able to reproduce a similar issue in Eclipse Oxygen. When I select
> > multiple lines and hit "delete"key it crashes eclipse:
> > 
> [...]
> > Stack:
> [...]
> > C  [libswt-pi-cocoa-4711.jnilib+0xbdb0]
> 
> This line shows that you are using an milestone build of Oxygen,
> Eclipse4.7M2.app
> 
> This bug was fixed in 4.7M7
Comment 18 Till Brychcy CLA 2017-10-12 01:33:15 EDT
(In reply to AMIT SUDHALKAR from comment #17)
> Is this the link to download the M7 version:
> 

4.7M7 is old by now, too.

If you'd download something today, I'd suggest 4.7.1a with java 9 and unit 5 support:

http://download.eclipse.org/eclipse/downloads/drops4/R-4.7.1a-201710090410/


or any of the packages on 

https://www.eclipse.org/downloads/eclipse-packages/
(I think they are still 4.7.1 based, without java 9 and unit 5)
Comment 19 AMIT SUDHALKAR CLA 2017-10-12 08:24:22 EDT
I don't have JDK9 so, downloaded Eclipse 4.7 M7 from the link:

https://www.eclipse.org/downloads/packages/release/Oxygen/M7


Eclipse About:

=================
Eclipse Java EE IDE for Web Developers.

Version: Oxygen Release Milestone 7 (4.7.0 M7)
Build id: 20170519-0031
=================



(In reply to Till Brychcy from comment #18)
> (In reply to AMIT SUDHALKAR from comment #17)
> > Is this the link to download the M7 version:
> > 
> 
> 4.7M7 is old by now, too.
> 
> If you'd download something today, I'd suggest 4.7.1a with java 9 and unit 5
> support:
> 
> http://download.eclipse.org/eclipse/downloads/drops4/R-4.7.1a-201710090410/
> 
> 
> or any of the packages on 
> 
> https://www.eclipse.org/downloads/eclipse-packages/
> (I think they are still 4.7.1 based, without java 9 and unit 5)
Comment 20 Andrey Loskutov CLA 2017-11-06 05:34:46 EST
*** Bug 526183 has been marked as a duplicate of this bug. ***
Comment 21 Julien Dehaudt CLA 2017-12-08 02:32:37 EST
Created attachment 271820 [details]
Neon crash log

Any thoughts to backport the fix into Neon ?

Some of our users are facing this crash when launching a debug session in our RCP based on Neon, and unfortunately, Oxygen integration is not in short terms plan...

Thanks guys.
Comment 22 Lakshmi P Shanmugam CLA 2017-12-08 07:43:20 EST
(In reply to Julien D from comment #21)
> Created attachment 271820 [details]
> Neon crash log
> 
> Any thoughts to backport the fix into Neon ?
> 
There are no more releases for Neon. Maintenance builds are available only for Oxygen (4.7).

The fix has been backported to the R4_6_maintenance branch [1], but as mentioned before there will be no builds from the R4_6 branch. You'll have to build the SWT jar with the new libraries yourself.

[1]
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?h=R4_6_maintenance&id=05ad9a7ee80cc8b6c65d65863a1226f3a6745c11
http://git.eclipse.org/c/platform/eclipse.platform.swt.binaries.git/commit/?h=R4_6_maintenance&id=d2025836e4cbce56fb212a9d7e802e6aca1bc99b
Comment 23 Till Brychcy CLA 2018-01-26 04:29:25 EST
*** Bug 528946 has been marked as a duplicate of this bug. ***
Comment 24 Lakshmi P Shanmugam CLA 2018-01-29 04:04:31 EST
*** Bug 527171 has been marked as a duplicate of this bug. ***
Comment 25 Sanket Gadiya CLA 2018-05-25 05:21:10 EDT
Is it possible to backport above changes in Eclipse 4.5.2 mars? 

I am trying to do these changes in Eclipse 4.5.2 Mars on OSX 10.13.4, that has Xcode 9.3. I also downloaded Xulrunner SDK 31 64bit for osx . But I am getting below compilation errors in building  libswt-xulrunner-cocoa-4530.jnilib. 
e.g. - 
[exec] xpcom.cpp:85:15: error: unknown type name 'nsStaticModuleInfo'
[exec] rc = (jint)((SWT_XREInitEmbedding)arg0)((nsILocalFile *)arg1, (nsILocalFile *)arg2, (nsIDirectoryServiceProvider *)arg3, (nsStaticModuleInfo const *)arg4, arg5);

[exec] xpcom.cpp:183:13: error: no matching function for call to 'NS_NewLocalFile'
[exec] rc = (jint)NS_NewLocalFile((nsAString *)arg0, arg1, (nsILocalFile*)lparg2);

[exec] xpcom.cpp:6836:13: error: use of undeclared identifier 'XPCOMGlueShutdown'
[exec] rc = (jint)XPCOMGlueShutdown();

Could you tell me how you are using xulrunner SDK to build macosx native jar?
Comment 26 prateek goyal CLA 2018-05-28 04:24:31 EDT
I am still seeing this issue in Oxygen Release Milestone 2 (4.7.0 M2).

My MacOS version is: 10.13.3 (17D102).
Comment 27 Dani Megert CLA 2018-05-28 06:15:41 EDT
(In reply to prateek goyal from comment #26)
> I am still seeing this issue in Oxygen Release Milestone 2 (4.7.0 M2).
> 
> My MacOS version is: 10.13.3 (17D102).

Of course you do. The fix went into M4.
Comment 28 Dani Megert CLA 2018-05-28 06:15:58 EDT
(In reply to Dani Megert from comment #27)
> (In reply to prateek goyal from comment #26)
> > I am still seeing this issue in Oxygen Release Milestone 2 (4.7.0 M2).
> > 
> > My MacOS version is: 10.13.3 (17D102).
> 
> Of course you do. The fix went into M4.

Sorry, M7.
Comment 29 prateek goyal CLA 2018-05-29 04:09:40 EDT
(In reply to Dani Megert from comment #28)
> (In reply to Dani Megert from comment #27)
> > (In reply to prateek goyal from comment #26)
> > > I am still seeing this issue in Oxygen Release Milestone 2 (4.7.0 M2).
> > > 
> > > My MacOS version is: 10.13.3 (17D102).
> > 
> > Of course you do. The fix went into M4.
> 
> Sorry, M7.

Thanks a lot. Sorry for incovenience.
Comment 30 Dani Megert CLA 2018-06-25 09:14:13 EDT
*** Bug 536245 has been marked as a duplicate of this bug. ***