Stefan Schimanski wrote:

Am 23.05.2007 um 11:34 schrieb Abdelrazak Younes:

Jean-Marc Lasgouttes wrote:
"Richard" == Richard Heck <[EMAIL PROTECTED]> writes:
Richard> This is from Text2.cpp, around line 1220. Since we do
Richard> now have multiple views, either there is a bug here or else
Richard> the warning can be removed.
I think we have a bug, but it is not easy to trigger :)

It's even more difficult than you can imagine because this use case below is working correctly here. All cursors are always valid ;-)

It's even much easier:

Put text "abcde" in two windows. Put the cursor of window 2 in the middle of the text. Select the text in window 2 and delete it. The cursor in window 2 is now invalid. Switch to Window 2 and crash!

The attached patch fixes that. It should fix also a number of other situation where cursor may be invalidated. I had to add a test in Cursor::fixIfBroken() for the case were we are not inside an Inset but in the main Text.

Abdel.
Index: Cursor.cpp
===================================================================
--- Cursor.cpp  (revision 18473)
+++ Cursor.cpp  (working copy)
@@ -1299,9 +1299,31 @@
 
 void Cursor::fixIfBroken()
 {
+       Cursor copy = *this;
+
+       if (depth() == 1) {
+               bool fixed = false;
+               if (pit() > lastpit()) {
+                       pit() = lastpit();
+                       pos() = 0;
+                       fixed = true;
+               }
+               else if(pos() > lastpos()) {
+                       pos() = lastpos();
+                       fixed = true;
+               }
+               if (fixed) {
+                       lyxerr << "correcting cursor to level " << depth() << 
endl;
+                       lyxerr << "old: " << copy << endl;
+                       lyxerr << "new: " << *this << endl;
+                       clearSelection();
+               }
+               return;
+       }
+
        // find out last good level
-       Cursor copy = *this;
        size_t newdepth = depth();
+
        while (!copy.empty()) {
                if (copy.idx() > copy.lastidx()) {
                        lyxerr << "wrong idx " << copy.idx()
Index: frontends/WorkArea.cpp
===================================================================
--- frontends/WorkArea.cpp      (revision 18473)
+++ frontends/WorkArea.cpp      (working copy)
@@ -140,9 +140,11 @@
 
        // No need to do anything if this is the current view. The BufferView 
        // metrics are already up to date.
-       if (&lyx_view_ != theApp()->currentView())
+       if (&lyx_view_ != theApp()->currentView()) {
                // FIXME: it would be nice to optimize for the off-screen case.
                buffer_view_->updateMetrics(false);
+               buffer_view_->cursor().fixIfBroken();
+       }
 
        updateScrollbar();
 

Reply via email to