commit 4fbb0f17707c51febda4dd66f059267f57a6db5a
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon Jun 19 12:23:17 2017 +0200

    Avoid crash when selecting long text
    
    In some (not yet understood) situations, the paragraph metrics cache
    is empty in generateSyntheticMouseEvent(). We just avoid a crash in
    this case, but there is probably an underlying problem that deserves
    being fixed.
    
    Fixes bug #10324.
    
    (cherry picked from commit 4efb129ccba448edfb851741089d70b0bfd054a3)
---
 src/TextMetrics.h                 |    2 ++
 src/frontends/qt4/GuiWorkArea.cpp |    8 +++++++-
 status.22x                        |    2 ++
 3 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index 016860b..dd74b2e 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -94,6 +94,8 @@ public:
        bool redoParagraph(pit_type const pit);
        /// Clear cache of paragraph metrics
        void clear() { par_metrics_.clear(); }
+       /// Is cache of paragraph metrics empty ?
+       bool empty() const { return par_metrics_.empty(); }
 
        ///
        int ascent() const { return dim_.asc; }
diff --git a/src/frontends/qt4/GuiWorkArea.cpp 
b/src/frontends/qt4/GuiWorkArea.cpp
index f46e400..6bf68cd 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -1009,12 +1009,18 @@ void GuiWorkArea::generateSyntheticMouseEvent()
 
        // In which paragraph do we have to set the cursor ?
        Cursor & cur = d->buffer_view_->cursor();
-       // FIXME: we don't know howto handle math.
+       // FIXME: we don't know how to handle math.
        Text * text = cur.text();
        if (!text)
                return;
        TextMetrics const & tm = d->buffer_view_->textMetrics(text);
 
+       // Quit gracefully if there are no metrics, since otherwise next
+       // line would crash (bug #10324).
+       // This situation seems related to a (not yet understood) timing 
problem.
+       if (tm.empty())
+               return;
+
        pair<pit_type, const ParagraphMetrics *> pp = up ? tm.first() : 
tm.last();
        ParagraphMetrics const & pm = *pp.second;
        pit_type const pit = pp.first;
diff --git a/status.22x b/status.22x
index 7621e07..763d16a 100644
--- a/status.22x
+++ b/status.22x
@@ -91,6 +91,8 @@ What's new
 
 - Fix random crash when dissolving inset (bug 10667).
 
+- Avoid crash when selecting long text (bug 10324).
+
 - Avoid a case of stuck cursor after entering an inset (bug 10630).
 
 

Reply via email to