Mubarrat Hasan
Mubarrat Hasan

Reputation: 304

UWP - Rich Edit Box throws exception when get or set multi-line text while math mode API is enabled

I have a RichEditBox in UWP. I've enabled math mode API using the following statement.

LimitedAccessFeatures.TryUnlockFeature(...);
RichEditBox.TextDocument.SetMathMode(RichEditMathMode.MathOnly);

When I type multi-line in this RichEditBox and call RichEditBox.TextDocument.GetText(TextGetOptions.FormatRtf, out string rtf) and RichEditBox.TextDocument.SetText(TextSetOptions.FormatRtf, value), it throws the following exception.

System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

It also has the same behavior in multi-line when using RichEditBox.LoadFromStream(...) and RichEditBox.SaveToStream(...).


And also when I type multi-line in this RichEditBox and call RichEditBox.TextDocument.GetMath(out string math), math returned an empty string. It works properly for single-line, but not multi-line.


To reproduce this

  1. Enable math mode API in RichEditBox.
  2. Set AcceptsReturn property to true.
  3. Type some multi-line text in RichEditBox.
  4. Call these following statements in that RichEditBox.
    1. RichEditBox.TextDocument.GetText(TextGetOptions.FormatRtf, out string rtf)
    2. RichEditBox.TextDocument.SetText(TextSetOptions.FormatRtf, value)
    3. RichEditBox.LoadFromStream(...)
    4. RichEditBox.SaveToStream(...)

What I've tried:

I figured out how to get a rich text from that RichEditBox using the following statement.

RichEditBox.TextDocument.SetMathMode(RichEditMathMode.NoMath);
RichEditBox.TextDocument.GetText(TextGetOptions.FormatRtf, out string rtf);
RichEditBox.TextDocument.SetMathMode(RichEditMathMode.MathOnly);

It works properly for RichEditBox.TextDocument.GetText(TextGetOptions, out string) method. But it doesn't work for RichEditBox.TextDocument.SetText(TextSetOptions, string) because if I call it, it sets only a line but not any characters. That means all character is set as '\0' and line as '\n'.

Upvotes: 0

Views: 104

Answers (0)

Related Questions