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

Bug 245178

Summary: SWT on GTK gets garbled after 7710 characters in a Text component
Product: [Eclipse Project] Platform Reporter: Rob Clevenger <rcleveng>
Component: SWTAssignee: Bogdan Gheorghe <gheorghe>
Status: CLOSED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: caniszczyk, ericwill, jamesblackburn+eclipse, konigsberg, loskutov, Mike_Wilson, snorthov
Version: 3.5Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
7711 characters
none
7800 characters none

Description Rob Clevenger CLA 2008-08-25 17:36:24 EDT
Created attachment 110847 [details]
7711 characters

Build ID: I20080617-2000

Steps To Reproduce:
I've seen this in Eclipse dialogs (mainly the BuildPathsBlock listing out the included and excluded nodes in the tree).  When you have too much text in a SWT control (7710 seems to be the magic number), it falls over and wraps on top of itself causing garbled text.

I made a simple Eclipse command handler with this code to demonstrate the problem.  update 7711 with some larger value to see the text get more garbled (as it is, only the 1st character looks off with 7711 characters since 7710 seems to be the limit where this starts wrapping.  This is NOT limited to Text components though, since I've seen in the in org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListLabelProvider

More information:
package foo.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.jface.dialogs.Dialog;

/**
 * Our sample handler extends AbstractHandler, an IHandler base class.
 * @see org.eclipse.core.commands.IHandler
 * @see org.eclipse.core.commands.AbstractHandler
 */
public class SampleHandler extends AbstractHandler {
	/**
	 * The constructor.
	 */
	public SampleHandler() {
	}

	/**
	 * the command has been executed, so extract extract the needed information
	 * from the application context.
	 */
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		MyDialog d = new MyDialog(window.getShell());
		d.open();
		return null;
	}

	static class MyDialog extends Dialog {
      protected MyDialog(Shell parentShell) {
        super(parentShell);
      }

      @Override
      protected Control createDialogArea(Composite parent) {
        StringBuilder s = new StringBuilder(100* 1000);
        for (int i=0; i < 7711; i++) {
          s.append((char) ((i % 26) + 65));
        }

        Composite c = (Composite) super.createDialogArea(parent);
        c.setLayout(new GridLayout(1, false));
        new Label(c, SWT.CENTER).setText("Hello World");

        Label l = new Label(c, SWT.NONE);
        l.setText(s.toString());
        l.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

        Text t = new Text(c, SWT.BORDER |SWT.SINGLE);
        t.setText(s.toString());
        t.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
        this.getShell().setSize(1010, 400);
        return c;
      }

      @Override
      public int open() {
        return super.open();
      }

	}
}
Comment 1 Rob Clevenger CLA 2008-08-25 17:36:50 EDT
Created attachment 110848 [details]
7800 characters
Comment 2 Steve Northover CLA 2008-08-25 17:39:10 EDT
This is a bug in the display driver for Linux.  Do we have a FAQ for this somewhere?
Comment 3 Rob Clevenger CLA 2008-08-25 17:54:38 EDT
I searched here for bugs, and also looked at http://www.eclipse.org/swt/faq.php and didn't find any mention of this.
Comment 4 Steve Northover CLA 2008-08-25 18:37:17 EDT
I was asking Bogdan if we has a FAQ but thanks for looking!  There is a problem in many display drivers (on Windows too) where long text gets garbled.  We've been unable to work around it.  I'll let Bogdan find the old bug report and mark this as a dup.

This bug gets reported every once in a while and there's not much we can do.  A GTK C program has the same failure.
Comment 5 Rob Clevenger CLA 2008-08-25 18:41:58 EDT
(In reply to comment #4)
> I was asking Bogdan if we has a FAQ but thanks for looking!  There is a problem
> in many display drivers (on Windows too) where long text gets garbled.  We've
> been unable to work around it.  I'll let Bogdan find the old bug report and
> mark this as a dup.
> 
> This bug gets reported every once in a while and there's not much we can do.  A
> GTK C program has the same failure.
> 

What's the bug # on GTK?

What about truncating read only text components, labels etc?  I'm getting bugs logged against me for my product that builds on top of eclipse for this in the Eclipse Build Paths page, truncating it there seems like sort of a hack to me.
Comment 6 Steve Northover CLA 2008-09-25 18:20:59 EDT
*** Bug 189050 has been marked as a duplicate of this bug. ***
Comment 7 Robert Konigsberg CLA 2008-09-25 18:29:02 EDT
Just adding my @google.com address to this issue.
Comment 8 Rob Clevenger CLA 2008-09-26 12:50:13 EDT
Can somebody on SWT provide the GTK bug # that this is dependent upon?

Thanks.!
Comment 9 Andrey Loskutov CLA 2008-12-05 07:59:51 EST
Is there any workaround available/possible?

I'm just curious: if this is a *display* driver, then:

1) Why this bug is limited only to GTK+ applications? I can see/edit such long lines perfectly in nedit and kwrite.
2) Are there *better* display drivers known, where GTK+ can render long lines, or is this just bug in GTK+ itself?

Comment 10 James Blackburn CLA 2008-12-05 08:16:26 EST
Ah, I see this a lot too -- it's especially annoying when debugging and the variables view detail pane tries to display data formatted as a very long string... 

Nice to know I don't just have a broken gtk.
Comment 11 James Blackburn CLA 2009-02-08 09:04:13 EST
There are a couple of upstream bugs:
Overlapping characters: http://bugzilla.gnome.org/show_bug.cgi?id=90919
Performance Issues with Long lines: http://bugzilla.gnome.org/show_bug.cgi?id=114337

The overlapping characters bug (90919) seems to pinpoint Cairo as the culprit...
Comment 12 Mike Wilson CLA 2009-05-05 10:38:23 EDT
Changing Version tag to something more believable.
Comment 13 Eric Williams CLA 2018-06-29 15:44:33 EDT
Upstream tickets seem to be fixed, going to close this one. Please reopen it if you continue to experience this issue on GTK3.22/4.8.