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

Bug 495008

Summary: GC#getClipping returns an empty rectangle on the latest version of CentOS 6
Product: [Eclipse Project] Platform Reporter: Peter Severin <peter>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: c_lamour, ericwill, yasunaka
Version: 4.6Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Test case for GC#getClipping bug none

Description Peter Severin CLA 2016-05-31 07:52:12 EDT
Created attachment 262126 [details]
Test case for GC#getClipping bug

GC#getClipping returns an empty [0, 0, 0, 0] clipping on CentOS 6. This bug is present with Eclipse 4.4, 4.5 and 4.6. I didn't test other versions.

I've reports of this bug from actual CentOS 6 users. The exact GTK version that is being used with latest updates is 2.24.23. Note that CentOS 6 is being fully supported until Q2 2017, and will get maintenance updates till 30 November 2020, so this version of GTK should be supported properly by SWT.

The exact code where the problem occurs is in GC#getSize, in the following if fragment:

if (OS.GTK_VERSION >= OS.VERSION(2, 24, 0)) {
	width[0] = OS.gdk_window_get_width(data.drawable);
	height[0] = OS.gdk_window_get_height(data.drawable);
} else {
	OS.gdk_drawable_get_size(data.drawable, width, height);
}

The "then" part of this if condition is being executed and returns an empty size. The "else" part actually returns the correct size, but version 2.24.23 doesn't fall there.

This bug affects GEF-based plugins that use it to draw to an SWT Image.

It might be the same problem as described in Bug 489741.

I'm attaching a snippet that reproduces this issue. The following code will cause the test case to draw a black rectangle on faulty systems:

  Rectangle clip = gc.getClipping();
  gc.setClipping(clip);

On supported system it will draw a red rectangle.
Comment 1 Nobuhiko Yasunaka CLA 2017-11-01 06:08:47 EDT
In the case of Eclipse 4.7 (Oxygen), the code is changed to

	if (data.drawable != 0) {
		width[0] = OS.gdk_window_get_width(data.drawable);
		height[0] = OS.gdk_window_get_height(data.drawable);
		return;
	}

So, Eclipse 4.7 still has same problem.

In the case of Eclipse 4.3, the OS.USE_CAIRO becomes true on the CentOS 6 environment, and data.drawable is 0. so Eclipse 4.3 skips the above code and runs  GC#getClipping() correctly. (Eclipse 4.3 does not check CAIRO version and set the OS.USE_CAIRO only with GTK version.)
Comment 2 Nobuhiko Yasunaka CLA 2017-11-07 05:42:49 EST
OS.gdk_drawable_get_size(data.drawable, width, height);
has already removed from Eclipse 4.7. Instead of that, 

OS.gdk_pixmap_get_size(data.drawable, width, height);
works fine in this case.
Comment 3 Christophe Lamour CLA 2017-12-11 11:28:15 EST
We have got the same issue with a rich Eclipse RCP client based on Eclipse 4.7.1.

Thanks to Peter for opening this bug and to Nobuhiko for providing the workaround, that works fine on RHEL/CentOS 6 but not on RHEL7 (but GC#getClipping() is working on RHEL 7).

But the use of OS#methods being discouraged, will this bug be corrected in a future release of SWT ?
Comment 4 Eric Williams CLA 2018-08-16 15:06:29 EDT
Is this still reproducible on GTK3.22 and 4.8?
Comment 5 Eric Williams CLA 2018-10-19 14:41:06 EDT
(In reply to Eric Williams from comment #4)
> Is this still reproducible on GTK3.22 and 4.8?

No response in awhile, please reopen this ticket if the issue reproduces on GTK3.22 with 4.9 or 4.10.