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

Bug 480852

Summary: [Cocoa] GC.copyArea() crashes application on OSX 10.11
Product: [Eclipse Project] Platform Reporter: Pavel Sakun <pavel.sakun>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: VERIFIED FIXED QA Contact:
Severity: blocker    
Priority: P3 CC: alex.tugarev, daniel_megert, lshanmug, markus.kell.r, mtucker, suag, tom.schindl
Version: 4.5.1   
Target Milestone: 4.6 M6   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:
Bug Depends on:    
Bug Blocks: 482454    
Attachments:
Description Flags
App crash report none

Description Pavel Sakun CLA 2015-10-28 06:55:59 EDT
Created attachment 257578 [details]
App crash report

After upgrading OSX to 10.11 our application started to crash on gc.copyArea() method call, the test case code is below:
    Display display = new Display();
    Shell shell = new Shell( display );
    Shell placeholder = new Shell( shell, 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( shell.getDisplay(), bsize.x, bsize.y );
    gc.copyArea( image, 0, 0 ); // Crashing
    gc.dispose();
    placeholder.close();
    shell.dispose();
    display.dispose();

Error reported is:
Assertion failed: (backing->lock_access > 0), function CGSBackingStoreUnlockReader, file Services/Windows/CGSBackingStore.c, line 400.

Console app shows the following:
10/28/15 13:51:46.427 java[68444]: WARNING: The Gestalt selector gestaltSystemVersion is returning 10.9.0 instead of 10.11.0. This is not a bug in Gestalt -- it is a documented limitation. Use NSProcessInfo's operatingSystemVersion property to get correct system version number.
Call location:
10/28/15 13:51:46.428 java[68444]: 0   CarbonCore                          0x00007fff8987c79f ___Gestalt_SystemVersion_block_invoke + 113
10/28/15 13:51:46.428 java[68444]: 1   libdispatch.dylib                   0x00007fff8e116453 _dispatch_client_callout + 8
10/28/15 13:51:46.428 java[68444]: 2   libdispatch.dylib                   0x00007fff8e11634b dispatch_once_f + 67
10/28/15 13:51:46.428 java[68444]: 3   CarbonCore                          0x00007fff8980909c _Gestalt_SystemVersion + 987
10/28/15 13:51:46.428 java[68444]: 4   CarbonCore                          0x00007fff898088b0 Gestalt + 139
10/28/15 13:51:46.429 java[68444]: 5   libswt-pi-cocoa-4528.jnilib         0x000000011ebce0ff Java_org_eclipse_swt_internal_cocoa_OS_Gestalt + 98
10/28/15 13:51:46.429 java[68444]: 6   ???                                 0x000000010f412758 0x0 + 4550895448
10/28/15 13:51:47.048 java[68444]: Set a breakpoint at CGSLogError to catch errors as they are logged.
10/28/15 13:51:47.048 java[68444]: lock_window_backing: Unable to lock window
10/28/15 13:51:47.083 diagnosticd[137]: error evaluating process info - pid: 68444, puniqueid: 68444
10/28/15 13:51:47.790 ReportCrash[68446]: Saved crash report for java[68444] version 1.0 (1.0) to /Users/pavel/Library/Logs/DiagnosticReports/java_2015-10-28-135147_EPBYMINW0773.crash
10/28/15 13:51:47.792 ReportCrash[68446]: Removing excessive log: file:///Users/pavel/Library/Logs/DiagnosticReports/java_2015-10-26-202822_EPBYMINW0773.crash
10/28/15 13:51:47.794 ReportCrash[68446]: AutoSubmitPreference is (null)

Crash report is attached.

While experimenting with the test code we found that the error doesn't occure if we add display.readAndDispatch() call before gc.copyArea() call. However, it was working without this call pretty well before and started failing only after upgrading to OSX 10.11. Is it the issue in our core/in OSX or SWT and what is the suggested fix here?
Comment 1 Pavel Sakun CLA 2015-10-29 12:00:34 EDT
Also observing the following warning message in console:

Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const: conn 0x2739b token 0x1ffffffffffe85
Oct 29 18:59:29  java[11425] <Warning>: Backtrace (at 300601):
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  0   CoreGraphics                        0x00007fff913350b4 CGSDisableUpdateToken + 155
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  1   AppKit                              0x00007fff87f5f4c3 ___disable_updates_sync_block_invoke_2 + 17
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  2   libdispatch.dylib                   0x00007fff8e116453 _dispatch_client_callout + 8
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  3   libdispatch.dylib                   0x00007fff8e117a3a _dispatch_barrier_sync_f_invoke + 74
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  4   AppKit                              0x00007fff87f5f391 NSCGSDisableUpdates + 1162
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  5   AppKit                              0x00007fff87f5ee12 NSCGSTransactionRunPreCommitActionsForOrder_ + 156
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  6   AppKit                              0x00007fff87f5ed59 NSCGSTransactionRunPreCommitActions_ + 21
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  7   AppKit                              0x00007fff887076de -[_NSCGSTransaction synchronize] + 42
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  8   AppKit                              0x00007fff88707851 NSCGSTransactionSynchronize + 76
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  9   AppKit                              0x00007fff884f3a19 -[NSSurface syncSurfaceWantsExtendedDynamicRange] + 150
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  10  AppKit                              0x00007fff88031d59 -[NSSurface _createSurface] + 677
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  11  AppKit                              0x00007fff880316b4 -[NSSurface setFrame:] + 785
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  12  AppKit                              0x00007fff88030fbe -[NSSurface syncToViewUnconditionally] + 174
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  13  AppKit                              0x00007fff88030c6c -[NSSurface orderSurface:relativeTo:] + 101
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  14  AppKit                              0x00007fff88124d0a NSOpenGLContextAttachOnScreenViewSurface + 183
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  15  AppKit                              0x00007fff8844b77b __27-[NSOpenGLContext setView:]_block_invoke + 192
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  16  AppKit                              0x00007fff87f4e0a9 NSPerformVisuallyAtomicChange + 147
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  17  AppKit                              0x00007fff88111ad1 -[NSOpenGLContext setView:] + 119
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  18  libawt_lwawt.dylib                  0x000000011a7853d7 +[GraphicsConfigUtil _getCGLConfigInfo:] + 1031
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  19  libawt_lwawt.dylib                  0x000000011a785921 Java_sun_java2d_opengl_CGLGraphicsConfig_getCGLConfigInfo + 256
Oct 29 18:59:29  java[11425] <Warning>: void CGSUpdateManager::log() const:  20  ???                                 0x0000000102c01e64 0x0 + 4341112420
Comment 2 Pavel Sakun CLA 2015-11-23 06:23:43 EST
While there was no any response from eclipse community, we solved the problem for ourselves, details are in http://jira.pentaho.com/browse/PDI-14470
Comment 3 Thomas Schindl CLA 2016-01-27 07:32:28 EST
The problem can be reproduced with an official snippet from jface - http://git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet061FakedNativeCellEditor.java

the offending lines are:

GC gc = new GC(shell);
Image image = new Image(control.getDisplay(), bsize.x, bsize.y);
gc.copyArea(image, 0, 0); // the line of crash
gc.dispose();
Comment 4 Thomas Schindl CLA 2016-01-27 07:33:49 EST
IMHO this is a serious crash which many applications will suffer from as many of them copied the trick in our snippet
Comment 5 Lakshmi P Shanmugam CLA 2016-03-14 15:02:05 EDT
Replaced the Quartz APIs with the NSView APIs to the copy the required area from a view onto an Image.
Fixed in master -- http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=b784258052e3ced6e92c72a28e1f035a0c72a2f3

Tested with the Snippet in comment 0, Snippet 95 & Snippet 215.
Comment 6 Lakshmi P Shanmugam CLA 2016-03-15 08:41:14 EDT
Verified in I20160314-2000