StackOverflowError for SWT Table and Patches

Pathes link

Table_Patched.class for org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar

Table_Patched.class for org.eclipse.swt.win32.win32.x86_64_3.6.1.v3655c.jar

You can also download the patched plugins with table pathced:

org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar

org.eclipse.swt.win32.win32.x86_64_3.6.1.v3655c.jar

Error:

Sometimes when you use swt table and remove multiple columns, maybe you get the following exception:

java.lang.StackOverflowError
	at org.eclipse.swt.internal.win32.OS.CallWindowProcW(Native Method)
	at org.eclipse.swt.internal.win32.OS.CallWindowProc(OS.java:2362)
	at org.eclipse.swt.widgets.Table.callWindowProc(Table.java:564)
	at org.eclipse.swt.widgets.Table.callWindowProc(Table.java:430)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4251)
	at org.eclipse.swt.widgets.Table.windowProc(Table.java:5779)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4886)
	at org.eclipse.swt.internal.win32.OS.SendMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.SendMessage(OS.java:3156)
	at ...

Maybe the usage is the same as SWT Table with SWT.VIRTUAL raises StackOverflowError , maybe not. It is no matter. 


Causes:

This is a bug existing in Window 7(both 32bits and 64bits), please refer to the bug from eclipse Bug 316813 - Stack overflow still happens in table on Windows 7. In fact this bug presents in swt-3.6.1-win32-win32-x86 and swt-3.6.2-win32-win32-x86. The bug is fixed in swt-3.7(Verified).


Solution:


Solution 1. In my development, due to some reasons we can not update swt version from 3.6 to 3.7. So I decide to make a patch for 3.6.1. Before all, we need to get the swt source code from Git. You can refer to this article Using SWT From Git, I will draft another blog named Get SWT Source Code From Git to demonstrate how to get swt source code.

When getting the source code of SWT, refer to the following changes to update the Table.java file. For swt_win32_X86, you can also get the patch from above link.

### Eclipse Workspace Patch 1.0
#P org.eclipse.swt
Index: Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java,v
retrieving revision 1.544
diff -u -r1.544 Table.java
--- Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java	31 May 2010 16:44:10 -0000	1.544
+++ Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java	14 Jun 2010 20:01:08 -0000
@@ -6579,7 +6579,22 @@
 			*/
 			if ((style & SWT.VIRTUAL) != 0 && !item.cached) {
 				if (ignoreShrink) {
-					OS.SendMessage (handle, OS.LVM_REDRAWITEMS, plvfi.iItem, plvfi.iItem);
+					/*
+					* Feature in Windows 7. Using LVM_REDRAWITEMS causes LVN_GETDISPINFO
+					* to be sent before the method returns. For this reason, LVM_REDRAWITEMS
+					* can never be used from a LVN_GETDISPINFO handler. The fix is to InvalidateRect()
+					* passing the bounds of the entire item.
+					*/
+					if (!OS.IsWinCE && OS.VERSION (6, 1) >= OS.WIN32_VERSION) {
+						RECT rect = new RECT ();
+						rect.left = OS.LVIR_BOUNDS;
+						ignoreCustomDraw = true;
+						int /*long*/ code = OS.SendMessage (handle, OS. LVM_GETITEMRECT, plvfi.iItem, rect);
+						ignoreCustomDraw = false;
+						if (code != 0) OS.InvalidateRect (handle, rect, true);
+					} else {
+						OS.SendMessage (handle, OS.LVM_REDRAWITEMS, plvfi.iItem, plvfi.iItem);
+					}
 					break;
 				}
 			}

Note: For swt_win32_X86_64 you have to change 

int /*long*/ code = OS.SendMessage (handle, OS. LVM_GETITEMRECT, plvfi.iItem, rect);
to
long code = OS.SendMessage (handle, OS. LVM_GETITEMRECT, plvfi.iItem, rect);


Solution 2. 

Update the swt with version 3.6 to 3.7.

-----------------

I have made a patch for swt_3.6.1_win32_x86, but BLOG does not support attachment, so...

你可能感兴趣的:(table,table,for,SWT,patch)