Bug 23406 - [Win32] StyledText/TextLayout render certain long lines as empty (was: Long lines are not displayed by editor)
Summary: [Win32] StyledText/TextLayout render certain long lines as empty (was: Long l...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows All
: P3 major with 9 votes (vote)
Target Milestone: 4.23 M1   Edit
Assignee: Jonah Graham CLA
QA Contact: Alexandr Miloslavskiy CLA
URL:
Whiteboard:
Keywords: performance
: 49867 68116 157312 182413 199991 201851 247834 256160 353197 371522 371547 372241 375202 388708 390576 443433 446862 453288 492066 517812 533293 537659 541104 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-09-11 09:28 EDT by Kai-Uwe Maetzel CLA
Modified: 2022-03-19 21:35 EDT (History)
45 users (show)

See Also:


Attachments
Snippet to find the limits (1.74 KB, text/plain)
2014-09-15 13:51 EDT, Markus Keller CLA
no flags Details
Native snippet to demonstrate various limits (15.91 KB, text/plain)
2018-10-26 12:20 EDT, Alexandr Miloslavskiy CLA
no flags Details
column 175 character invisible in text editor (29.32 KB, application/octet-stream)
2019-10-23 14:31 EDT, Farzi Pourmoetamed CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kai-Uwe Maetzel CLA 2002-09-11 09:28:46 EDT
See bug #23305.

I am debugging an application that has XML text.  This results in very large
strings or files with no line seperators.  For example, one of my files has a
line with 27,000 characters.  Such large unbroken lines cause eclipse problems
in a number of areas.

1) The editor simply cannot handle such a large line and ends up throwing an
exception warning.  The line is a mess of characters.  It looks line the line is
overwriting itself.
Comment 1 Claude Knaus CLA 2002-09-16 04:16:01 EDT
It's a StyledText bug.

StyledText seems to wrap around if a line contains more than ~12530 bytes.
This seems to be the case for linux-gtk as well.
Here's the test case:
---8<---
package bugs;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class LongLinesBug {

	private static String createLongLine() {
		StringBuffer buffer= new StringBuffer();
		for (int i= 0; i < 1253; ++i) {
			String string= "" + (i * 10);
			buffer.append(string);	
			for (int j= string.length(); j != 10; ++j)		
	
				buffer.append(' ');
		}		
		return buffer.toString();
	}

	public static void main(String[] args) {
		Display display= new Display();
		Shell shell= new Shell();
		StyledText text= new StyledText(shell, SWT.NONE);
		text.setText(createLongLine());
		
		shell.setLayout(new FillLayout());
		shell.pack();
		shell.open();
		
		while (!shell.isDisposed())
			if (!display.readAndDispatch())
				display.sleep();
			
		display.dispose();		
	}
}
Comment 2 Steve Northover CLA 2003-03-04 22:22:37 EST
Bug in Windows.  We can't work around this because it depends on the display 
driver and we can't determine the limit programatically.  Funny that the GTK 
display driver seems to have the same bug.
Comment 3 Bogdan Gheorghe CLA 2007-04-18 17:08:07 EDT
*** Bug 182413 has been marked as a duplicate of this bug. ***
Comment 4 Bogdan Gheorghe CLA 2007-05-31 10:59:45 EDT
*** Bug 189050 has been marked as a duplicate of this bug. ***
Comment 5 Dani Megert CLA 2007-06-26 03:15:39 EDT
*** Bug 49867 has been marked as a duplicate of this bug. ***
Comment 6 Bogdan Gheorghe CLA 2007-08-15 11:10:05 EDT
*** Bug 199991 has been marked as a duplicate of this bug. ***
Comment 7 Dani Megert CLA 2007-08-31 02:40:20 EDT
*** Bug 201851 has been marked as a duplicate of this bug. ***
Comment 8 Robert Konigsberg CLA 2007-08-31 02:53:02 EDT
So does someone have a recommendation for addressing this particular bug?  If it's a GTK issue on Linux, has it been reported? If not, can someone who understands the problem help by reporting it?

If you haven't figured out, I would really like to see this resolved. :)
Comment 9 Doug Schaefer CLA 2007-10-19 13:02:55 EDT
*** Bug 68116 has been marked as a duplicate of this bug. ***
Comment 10 Bogdan Gheorghe CLA 2008-12-22 10:50:24 EST
*** Bug 247834 has been marked as a duplicate of this bug. ***
Comment 11 Felipe Heidrich CLA 2011-07-27 11:39:09 EDT
*** Bug 353197 has been marked as a duplicate of this bug. ***
Comment 12 Dani Megert CLA 2012-02-15 04:41:05 EST
*** Bug 371522 has been marked as a duplicate of this bug. ***
Comment 13 Dani Megert CLA 2012-02-15 04:42:24 EST
*** Bug 157312 has been marked as a duplicate of this bug. ***
Comment 14 Dani Megert CLA 2012-02-15 04:42:29 EST
*** Bug 256160 has been marked as a duplicate of this bug. ***
Comment 15 Dani Megert CLA 2012-02-15 04:44:15 EST
*** Bug 371547 has been marked as a duplicate of this bug. ***
Comment 16 Dani Megert CLA 2012-02-22 10:23:40 EST
*** Bug 372241 has been marked as a duplicate of this bug. ***
Comment 17 Dani Megert CLA 2012-04-11 08:44:47 EDT
*** Bug 375202 has been marked as a duplicate of this bug. ***
Comment 18 Dani Megert CLA 2012-09-04 02:17:20 EDT
*** Bug 388708 has been marked as a duplicate of this bug. ***
Comment 19 Markus Keller CLA 2014-09-15 12:40:35 EDT
(In reply to Steve Northover from comment #2)
> we can't determine the limit programatically.

Yes we can, at least well enough to know when it starts to get fishy. When I add the following in TextLayout#shape(long, StyleItem) line 3501 right after "OS.ScriptPlace(..., abc);", then I get a horizontal scroll bar and see logging output as soon as the line goes empty:

	if (chars.length > 100 && abc[1] == 0) {
		abc[1]= 10 * chars.length;
		System.out.println("bug, setting abc[1] to " + abc[1]);
	}

We can use a more conservative limit, but you get the point. I know a run can contain 101+ zero-width characters, but it's perfectly OK to make that case more expensive.

This bug has too many dups for a WONTFIX. Reopening. The right solution would be to render runs in smaller chunks when the OS is incapable to comply.

A maybe less complex solution would be to just render as many characters as possible and then draw something like ###OS_GRAPHICS_LIMIT_REACHED### or write the problem to System.err.
Comment 20 Markus Keller CLA 2014-09-15 12:43:44 EDT
*** Bug 443433 has been marked as a duplicate of this bug. ***
Comment 21 Markus Keller CLA 2014-09-15 13:51:59 EDT
Created attachment 247084 [details]
Snippet to find the limits

Note that the Windows bug is not bound by the character count but depends on the actual line contents! The attached snippet finds the upper limit for the pattern from comment 1.

If you use the commented pattern construction method
//			String string = "x" + (i * 10); // works!
, then it works with lines that are millions of characters long.
Comment 22 Niraj Modi CLA 2015-05-04 13:35:58 EDT
Hi Markus, are you working on a fix for Mars ?
Comment 23 Markus Keller CLA 2015-05-05 13:55:38 EDT
(In reply to Niraj Modi from comment #22)
> Hi Markus, are you working on a fix for Mars ?

No, I had not planned to, but I would support a fix in RC1.
Comment 24 Dani Megert CLA 2016-04-20 06:29:02 EDT
*** Bug 492066 has been marked as a duplicate of this bug. ***
Comment 25 Nobody - feel free to take it CLA 2016-07-21 15:42:03 EDT
This can be worked around with Word wrap (Alt+Shift+Y), at least with PDT.
Comment 26 Arun Thondapu CLA 2017-06-06 07:34:48 EDT
*** Bug 517812 has been marked as a duplicate of this bug. ***
Comment 27 Arun Thondapu CLA 2017-06-14 05:22:56 EDT
*** Bug 453288 has been marked as a duplicate of this bug. ***
Comment 28 Dani Megert CLA 2018-04-06 04:44:48 EDT
*** Bug 533293 has been marked as a duplicate of this bug. ***
Comment 29 Dani Megert CLA 2018-08-03 09:42:42 EDT
*** Bug 537659 has been marked as a duplicate of this bug. ***
Comment 30 Alexandr Miloslavskiy CLA 2018-10-22 10:01:09 EDT
Before I start working on this, is there someone else trying to fix it at the moment?
Comment 31 Alexandr Miloslavskiy CLA 2018-10-26 12:19:44 EDT
The issue turned out to be quite complicated, with multiple different limits in it.

Problem 1: 'ScriptShape' WINAPI fails with E_FAIL for OpenType fonts when the length of the string is over 32000 (0x7d00) characters
--------------------------------
Notes:
a) 32000 is hardcoded in 'gdi32full!GenericEngineGetGlyphs' Windows function. So it's not exactly a bug, just lack of documentation.
b) 'gdi32full!GenericEngineGetGlyphs' is called with this stack:
	gdi32full!GenericEngineGetGlyphs
	gdi32full!ShapingGetGlyphs
	gdi32full!ShlShapeOT
	gdi32full!ScriptShape
c) 32000 explains why attached snippet fails beginning with 3201 (it creates 10 characters per every 'ten').
d) Setting 'SCRIPT_ANALYSIS.fNoGlyphIndex' to 'TRUE' causes 'gdi32full!ScriptShape' to call 'gdi32full!GDIShape' instead, which does not have this limit.
e) Using non-OpenType font causes causes 'gdi32full!ScriptShape' to call 'gdi32full!NumShape' instead, which does not have this limit.

Problem 2: 'ScriptShape' WINAPI fails with E_INVALIDARG when "maximum glyphs" parameter is over 65535 (0xffff) characters
--------------------------------
Notes:
a) "maximim glyphs" of 65535 means no more then 43679 characters.
b) 'SCRIPT_ANALYSIS.fNoGlyphIndex' does not help here.
c) Non-OpenType font does not help here.
d) I didn't research if there are other workarounds.

Problem 3: 'ScriptPlace' WINAPI fails with E_FAIL when the length of the string is over 32000 (0x7d00) characters
--------------------------------
Notes:
a) 'SCRIPT_ANALYSIS.fNoGlyphIndex' still helps.
b) Non-OpenType font does not help here.

Problem 4: 'ScriptTextOut' WINAPI fails with E_FAIL when drawn area exceeds 32767 (0x7ffff) pixels
--------------------------------
a) Limiting number of characters depends on font size.
b) 'SCRIPT_ANALYSIS.fNoGlyphIndex' does not help here.
c) Non-OpenType font still helps.
d) I didn't test for precise number here. Maybe it's 32768 instead.

Overall
--------------------------------
Of these problems, for #2 I don't have known workarounds.
This probably means that splitting text into smaller runs is unavoidable.
Comment 32 Alexandr Miloslavskiy CLA 2018-10-26 12:20:35 EDT
Created attachment 276390 [details]
Native snippet to demonstrate various limits
Comment 33 Lakshmi P Shanmugam CLA 2018-12-03 01:50:55 EST
Moving out of 4.10. Please re-target as required.
Comment 34 thomas menzel CLA 2018-12-31 11:28:22 EST
even if this is not fixable in the short term, maybe its possible to show a warning/error box when opening an editor that has such long lines.

the current behavior, just to let the editor run into these display bugs is really unacceptable b/c i never would have expected that such issues would still exist these days. 
but then again, windows also still has a limit of 250 chars in a normal path -- so i guess i should have known and not get so puzzled over not seeing all of my long un-pretty json string in the editor.
:sigh:
Comment 35 Andrey Loskutov CLA 2018-12-31 11:32:32 EST
Using word wrap is not an option here?
Comment 36 Jonah Graham CLA 2018-12-31 12:55:22 EST
(In reply to Andrey Loskutov from comment #35)
> Using word wrap is not an option here?

Not really. In CDT we are indeed preventing word wrap in some cases because of Bug 168557
Comment 37 Nikita Nemkin CLA 2019-05-27 16:59:26 EDT
*** Bug 541104 has been marked as a duplicate of this bug. ***
Comment 38 Paul Pazderski CLA 2019-07-26 08:58:55 EDT
*** Bug 446862 has been marked as a duplicate of this bug. ***
Comment 39 Farzi Pourmoetamed CLA 2019-10-23 14:28:08 EDT
Hello, I also have a customer with a problem similar to 492066 (duplicate of this one):
- using the base Eclipse 4.6.3 
- have a file with 10008 long lines (only 3) and the character on column 175 is invisible unless the length is reduce to 4854. OR, if they remove the character (such as N or O) from the line and then use "Undo", the character on column 175 is displayed in the text editor.
This is specially more visible when you compare 2 files (with the same length) where the only difference is the character in column 175. The compare works but it cannot display the character in column 175.
I will attach the 2 sample files that you can test with the text editor.
Comment 40 Farzi Pourmoetamed CLA 2019-10-23 14:31:58 EDT
Created attachment 280390 [details]
column 175 character invisible in text editor
Comment 41 Ievgen Mukhin CLA 2019-10-28 07:39:20 EDT
Hello, just encountered this bug. I've spent 4 hours of debugging why information is missing after exporting 3D scene from Autodesk Maya to Collada format until I realized, that it's Eclipse simply not displaying the text. The exported file is in xml format containing a lot of text beetween opening and closing tags (<p> lots of text here </p>). Eclipse was just showing "<p> </p>" and it was very hard to guess that text was hidden by editor.

I think this bug definitely should be fixed ASAP, nobody expects that editor hides information. There is no such problem when opening same file in Windows Notepad or FAR editor.
Comment 42 Nikita Nemkin CLA 2020-02-08 05:46:18 EST
*** Bug 390576 has been marked as a duplicate of this bug. ***
Comment 43 Jonah Graham CLA 2021-11-08 15:27:30 EST
(In reply to Alexandr Miloslavskiy from comment #31)
> Overall
> --------------------------------
> Of these problems, for #2 I don't have known workarounds.
> This probably means that splitting text into smaller runs is unavoidable.

Hi Alexandr  - I am coming back to this bug again and the native example you gave was very useful to understand the problem.

Did you ever propose a solution or come up with anything to split the text into smaller runs?
Comment 44 Alexandr Miloslavskiy CLA 2021-11-08 15:30:53 EST
Not really. Shortly after posting the summary I switched to other tasks and never really came back to this one.
Comment 45 Jonah Graham CLA 2021-11-10 09:15:15 EST
Alexandr in comment #31 identified a number of failure conditions in the win32 API that could cause this visible bug. I think I have a fix for at least some of the issues, including adding some of the missing error handling. Stay tuned for a gerrit or two in the coming days.
Comment 46 Eclipse Genie CLA 2021-11-12 17:02:25 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/187688
Comment 47 Eclipse Genie CLA 2021-11-12 17:02:34 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/187690
Comment 48 Eclipse Genie CLA 2021-11-12 17:02:53 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/187689
Comment 49 Eclipse Genie CLA 2021-11-12 17:03:02 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/187687
Comment 52 Niraj Modi CLA 2021-12-08 01:26:30 EST
Thanks Jonah for the bug fix and Alexandr for the review/test.

Resolving now.
Comment 53 Niraj Modi CLA 2022-01-06 04:55:01 EST
Verified using 100k+ characters in single line on Win10 using Build id: I20220106-0000
Comment 54 Jonah Graham CLA 2022-01-10 15:15:18 EST
Thanks Niraj for verifying this.

The fix works for me too on current releases on Windows. However it still can fail on older versions. I have access now to a Windows Server 2016 (which goes mainstream EOL tomorrow) and it still demonstrates this problem on shorter lines. AFAICT it shows Problem 4 from Comment 31. I suspect this will be fixed by a full implementation of https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/187695 (Bug 577238)
Comment 55 Nobody - feel free to take it CLA 2022-01-10 18:26:09 EST
Thank you Jonah
Should this then be reopened? Could someone at least indicate which Windows versions would qualify as "current"?
Comment 56 Jonah Graham CLA 2022-01-10 18:37:49 EST
I'm of two minds on reopening. This bug is fixed on supported platforms (afaik). 

As for what is supported, that is defined in https://www.eclipse.org/projects/project-plan.php?planurl=http://www.eclipse.org/eclipse/development/plans/eclipse_project_plan_4_23.xml target environments.
Comment 57 Nobody - feel free to take it CLA 2022-01-11 08:20:59 EST
Thank you Jonah. But I am afraid that only defines which environments are methodically tested. So other environments may or may not be supported.

Unfortunately, I am not aware of an actual description of what platforms are supported.

In any case, it would be good if we could determine which minimum Windows version(s) are needed for the fix to apply.
Comment 58 Jonah Graham CLA 2022-01-11 09:07:30 EST
(In reply to Philippe Cloutier from comment #57)
> In any case, it would be good if we could determine which minimum Windows
> version(s) are needed for the fix to apply.

:-) Please provide any such details. Windows 10 (i.e. the target platform from the plan) is supported. I have sporadic access to a Windows Server 2016 to test against. I don't have access to Windows 7, 8 or any other old version.
Comment 59 thomas menzel CLA 2022-01-18 14:27:16 EST
wow, this took almost 20 years. gratz for staying that long alive as a viable IDE
Comment 60 Alexandr Miloslavskiy CLA 2022-03-19 21:35:42 EDT
@Jonah unfortunately this caused regression, see Bug 579335