Le 08/03/2017 à 10:45, Helge Hafting a écrit :
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)

Thanks Helge for the nice analysis. This problem is not in master and is new to 2.2.3dev.

Here is a proposed patch, which sounds clear to me (no status.22x needed). Richard?

JMarc
>From 49c2329fdd1727bd9df14493abaed9714dbd92db Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Fri, 10 Mar 2017 19:54:15 +0100
Subject: [PATCH] Fix crash when adding newline at the end of a paragraph

This is a regression at b0673bd1. The code referred to row.pit(),
which was not correctly initialized in this case. The bug does not
exist in master, since the code in redoParagraph has been cleaned-up
and row.pit() is always correct.

Two corrective measures are taken, each of which would fix the bug:
- do not use row.pit() in breakRow, but directly the pit parameter.
- initialize row.pit() correctly in the faulty case.
---
 src/TextMetrics.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 280c90a..8f62eed 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -481,6 +481,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
 			pm.rows().push_back(Row());
 		Row & row = pm.rows()[row_index];
 		row.pos(first);
+		row.pit(pit);
 		breakRow(row, right_margin, pit);
 		setRowHeight(row, pit);
 		row.setChanged(false);
@@ -932,8 +933,8 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
 
 	// if the row is too large, try to cut at last separator. In case
 	// of success, reset indication that the row was broken abruptly.
-	int const next_width = max_width_ - leftMargin(max_width_, row.pit(), row.endpos())
-		- rightMargin(row.pit());
+	int const next_width = max_width_ - leftMargin(max_width_, pit, row.endpos())
+		- rightMargin(pit);
 
 	row.shortenIfNeeded(body_pos, width, next_width);
 	row.right_boundary(!row.empty() && row.endpos() < end
-- 
2.9.3

Reply via email to