Den 07. mars 2017 22:01, skrev Jean-Marc Lasgouttes:
FWIW, I can reproduce it. I'll have a look when I can.
I have debugged some more, and the problem is with explicit linebreaks
(ctrl+enter)
To crash:
start lyx, new document
type a word, press enter. (We need a normal paragraph first)
type another word in the second paragrap, press ctrl+enter
LyX dies immediately with:
lassert.cpp (51): ASSERTION pos <= par.size() VIOLATED IN
TextMetrics.cpp:1691
I don't know if there is something wrong, or if the assertion itself is
the problem. The assert is in the beginning of TextMetrics::leftMargin()
I tried printing "pos" and "par.size()" before the assert. While typing
the test words, "par.size increase" start at 0 at the beginning of each
paragraph, and increase. "pos" alternate between 0 and the same value as
par.size() I get two printouts per character typed
Example typing
abc<enter>
abcdefghij<ctrl+enter (and then lyx crashes)>
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 1
pos= 1 par.size()= 1
pos= 0 par.size()= 2
pos= 2 par.size()= 2
pos= 0 par.size()= 3
pos= 3 par.size()= 3
pos= 0 par.size()= 3
pos= 3 par.size()= 3
pos= 0 par.size()= 0
pos= 0 par.size()= 0
pos= 0 par.size()= 1
pos= 1 par.size()= 1
pos= 0 par.size()= 2
pos= 2 par.size()= 2
pos= 0 par.size()= 3
pos= 3 par.size()= 3
pos= 0 par.size()= 4
pos= 4 par.size()= 4
pos= 0 par.size()= 5
pos= 5 par.size()= 5
pos= 0 par.size()= 6
pos= 6 par.size()= 6
pos= 0 par.size()= 7
pos= 7 par.size()= 7
pos= 0 par.size()= 8
pos= 8 par.size()= 8
pos= 0 par.size()= 9
pos= 9 par.size()= 9
pos= 0 par.size()= 10
pos= 10 par.size()= 10
pos= 0 par.size()= 3
pos= 3 par.size()= 3
pos= 10 par.size()= 11
pos= 0 par.size()= 11
pos= 11 par.size()= 11
pos= 11 par.size()= 11
pos= 11 par.size()= 3
lassert.cpp (51): ASSERTION pos <= par.size() VIOLATED
As we see, TextMetrics is called several times per keypress. (Usually 2)
At first, par.size() counts up to 3 while typing abc
then, par.size() counts up to 10 as I type abcdefghij in the second
paragraph.
As I type ctrl+enter, there are more calls to TextMetrics. Some with
par.size()=11 which is the length of the second paragraph, but also some
with par.size()=3 which is the length of the first paragraph.
Combining the short length of the first paragraph with the current
position in the longer second paragraph yields the combination that
crashes LyX.
If I type the longer line first, followed by the second line and
ctrl+enter, there is no crash because the current position of the short
line is then combined with the length of the longer previous line.
It seems to me that there are possibly some unnecessary calls to
TextMetrics, as I can't see the point of working with the combination of
"cursor position in this paragraph, and character count of the previous
paragraph." Especially when a position beyond the end of the paragraph
is considered illegal, and different paragraphs may differ in length.
Helge Hafting