Reintroduce simple text analysis escape without crash or box drawing issue #9258

Closed
opened 2026-01-31 01:49:56 +00:00 by claunia · 3 comments
Owner

Originally created by @DHowett on GitHub (Jun 24, 2020).

Originally assigned to: @miniksa on GitHub.

Notes from bugs:

From #6488

When I run this in PowerShell (7),

"`e[30;47m`u{2500} What `u{2500}`e[m"

the text comes out without antialiasing. It looks like it's being drawn with FillGeometry just like a box drawing glyph.

image

If I flip the colors, it comes out antialiased.

image

Okay, this is because we're not populating _glyphClusters when text is "simple". When we go to split the run later (we split runs for things other than text analysis!), we try to remap the glyph clusters around the split.

Inevitably, we end up falling into DrawGlyphRun with run.glyphCount = 0 because _SplitCurrentRun stomped the glyphCount because there was no glyph cluster mapping.

Somehow magically we end up doing a "get raw geometry, draw" for the entire string which very handily hides the glyph clustering bug!

This fix works but I do not believe it is correct:

diff --git a/src/renderer/dx/CustomTextLayout.cpp b/src/renderer/dx/CustomTextLayout.cpp
index d19d2d0c3..395a58224 100644
--- a/src/renderer/dx/CustomTextLayout.cpp
+++ b/src/renderer/dx/CustomTextLayout.cpp
@@ -336,6 +336,7 @@ CustomTextLayout::CustomTextLayout(gsl::not_null<IDWriteFactory1*> const factory
             for (size_t i = glyphStart; i < _glyphAdvances.size(); i++)
             {
                 _glyphAdvances.at(i) = (float)_glyphDesignUnitAdvances.at(i) / designUnitsPerEm * _format->GetFontSize() * run.fontScale;
+                _glyphClusters.at(i) = static_cast<UINT16>(i);
             }

             run.glyphCount = textLength;

I'm worried about that "magical" rendering fallthrough. With this fix, are we striking the text twice -- once as a geometry and once as a glyph run?

(I commented out the glyph run drawing, and I think the answer is no.)

From #6664

Terminal crashed. In debug configuration raised exception in "vector" include file in
function void _Verify_offset(const difference_type _Off) const at line 113
"cannot seek vector iterator after end"

Call stack:
...
problem at
src\renderer\dx\CustomTextLayout.cpp at line 867:
const auto postOriginX = std::accumulate(_glyphAdvances.begin() + run.glyphStart,
_glyphAdvances.begin() + run.glyphStart + run.glyphCount,
mutableOrigin.x);

_glyphAdvances.size(): 0x000000000000001f
run.glyphStart: 0x00000001
run.glyphCount: 0x0000ffff

Same problem in wsl2 (Ubuntu or CentOS not matter) with Midnight Commander... start ok (in user's home directory) but Terminal crashes when trying cd to /home directory with mouse double click under .. or with cd .. in command line.
@igorkuzuro

Originally created by @DHowett on GitHub (Jun 24, 2020). Originally assigned to: @miniksa on GitHub. Notes from bugs: From #6488 > When I run this in PowerShell (7), > > ``` > "`e[30;47m`u{2500} What `u{2500}`e[m" > ``` > > the text comes out without antialiasing. It looks like it's being drawn with FillGeometry just like a box drawing glyph. > > ![image](https://user-images.githubusercontent.com/189190/84561566-4e18a800-ad02-11ea-89b8-fe4cc58127bb.png) > > If I flip the colors, it comes out antialiased. > > ![image](https://user-images.githubusercontent.com/189190/84561569-58d33d00-ad02-11ea-83c0-56b763950ae4.png) > Okay, this is because we're not populating `_glyphClusters` when text is "simple". When we go to split the run later (**we split runs for things other than text analysis!**), we try to remap the glyph clusters around the split. > > Inevitably, we end up falling into DrawGlyphRun with `run.glyphCount` = 0 because `_SplitCurrentRun` stomped the glyphCount because there was no glyph cluster mapping. > > Somehow _magically_ we end up doing a "get raw geometry, draw" for the entire string which very handily hides the glyph clustering bug! > > This fix _works_ but I do not believe it is correct: > > ```diff > diff --git a/src/renderer/dx/CustomTextLayout.cpp b/src/renderer/dx/CustomTextLayout.cpp > index d19d2d0c3..395a58224 100644 > --- a/src/renderer/dx/CustomTextLayout.cpp > +++ b/src/renderer/dx/CustomTextLayout.cpp > @@ -336,6 +336,7 @@ CustomTextLayout::CustomTextLayout(gsl::not_null<IDWriteFactory1*> const factory > for (size_t i = glyphStart; i < _glyphAdvances.size(); i++) > { > _glyphAdvances.at(i) = (float)_glyphDesignUnitAdvances.at(i) / designUnitsPerEm * _format->GetFontSize() * run.fontScale; > + _glyphClusters.at(i) = static_cast<UINT16>(i); > } > > run.glyphCount = textLength; > ``` > > I'm worried about that "magical" rendering fallthrough. With this fix, are we striking the text twice -- once as a geometry and once as a glyph run? > > (I commented out the glyph run drawing, and I think the answer is _no_.) From #6664 > Terminal crashed. In debug configuration raised exception in "vector" include file in > function void _Verify_offset(const difference_type _Off) const at line 113 > **"cannot seek vector iterator after end"** > > Call stack: > ... > problem at > src\renderer\dx\CustomTextLayout.cpp at line 867: > const auto postOriginX = std::accumulate(_glyphAdvances.begin() + run.glyphStart, > _glyphAdvances.begin() + run.glyphStart + run.glyphCount, > mutableOrigin.x); > > _glyphAdvances.size(): 0x000000000000001f > run.glyphStart: 0x00000001 > run.glyphCount: 0x0000ffff > > Same problem in wsl2 (Ubuntu or CentOS not matter) with Midnight Commander... start ok (in user's home directory) but Terminal crashes when trying cd to /home directory with mouse double click under .. or with cd .. in command line. > @igorkuzuro
Author
Owner

@DHowett commented on GitHub (Jun 24, 2020):

Reverted in #6665.

@DHowett commented on GitHub (Jun 24, 2020): Reverted in #6665.
Author
Owner

@DHowett commented on GitHub (Jun 24, 2020):

/cc @skyline75489

Michael's offered to bring this back, so there's no direct action required from you right now. Make sure you're on the review! 😄

@DHowett commented on GitHub (Jun 24, 2020): /cc @skyline75489 Michael's offered to bring this back, so there's no direct action required from you right now. Make sure you're on the review! :smile:
Author
Owner

@ghost commented on GitHub (Jul 22, 2020):

:tada:This issue was addressed in #6695, which has now been successfully released as Windows Terminal Preview v1.2.2022.0.🎉

Handy links:

@ghost commented on GitHub (Jul 22, 2020): :tada:This issue was addressed in #6695, which has now been successfully released as `Windows Terminal Preview v1.2.2022.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.2.2022.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#9258