I tried to dig into bug 1719 ("find next change" triggers assertion). This is 
what happens in short:

- ControlChanges::find calls lyxfind::findNextChange
- lyxfind::findNextChange calls lyxfind::findChange
- findChange calls cur.paragraph().lookupChange(cur.pos()) for (; cur; 
cur.forwardChar())

Now lookupChange asserts because of
BOOST_ASSERT(empty() || pos < size());
whereas cur.pos() actually *can* become == cur.paragraph().size() (when 
cur.forwardChar() reaches the end of a par)!

Now the question is: should cur.pos() be always < size()? And if so, why isn't 
that the case?

The attached patch is certainly not the correct fix, but it shows how the 
assertion(s) can be suppressed. It shows furthermore that the change tracker 
(at least tracking, merging, accepting, rejecting of changes) seem to work 
without the assertions, so fixing the assertions would be a worthy goal.

Anyway, I need some help to fix the thing properly.

Jürgen  
Index: changes.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/changes.C,v
retrieving revision 1.9
diff -p -u -r1.9 changes.C
--- changes.C	6 Oct 2003 15:42:07 -0000	1.9
+++ changes.C	19 Dec 2004 16:05:17 -0000
@@ -349,7 +349,7 @@ Change::Type Changes::lookup(pos_type po
 	}
 
 	check();
-	BOOST_ASSERT(0);
+	//BOOST_ASSERT(0);
 	return Change::UNCHANGED;
 }
 
Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.394
diff -p -u -r1.394 paragraph.C
--- paragraph.C	30 Nov 2004 01:59:34 -0000	1.394
+++ paragraph.C	19 Dec 2004 16:05:21 -0000
@@ -1665,14 +1665,14 @@ void Paragraph::cleanChanges()
 
 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
 {
-	BOOST_ASSERT(empty() || pos < size());
+	BOOST_ASSERT(empty() || pos <= size());
 	return pimpl_->lookupChange(pos);
 }
 
 
 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
 {
-	BOOST_ASSERT(empty() || pos < size());
+	BOOST_ASSERT(empty() || pos <= size());
 	return pimpl_->lookupChangeFull(pos);
 }

Reply via email to