[patch] LyX crashes with multiple views, #3785

2007-06-08 Thread Stefan Schimanski
If we want multiple views and update the cursors when switching, we  
should do it properly, maybe somehow similar to the patch below.


The bug: http://bugzilla.lyx.org/show_bug.cgi?id=3785

Stefan

Index: lyx-devel/src/DocIterator.cpp
===
--- lyx-devel.orig/src/DocIterator.cpp	2007-05-29 08:36:01.0  
+0200

+++ lyx-devel/src/DocIterator.cpp   2007-06-08 19:35:53.0 +0200
@@ -562,46 +562,58 @@
{
bool fixed = false;
-   for (size_t i = slices_.size() - 1; i != 0; --i)
+   // The top level CursorSlice should always be valid.
+   BOOST_ASSERT(slices_.size() == 0 || slices_[0].isValid());
+   
+	// cut off from the first invalid slice, and correct slices if  
possible

+   for (size_t i = 0; i < slices_.size(); ++i) {
+   // invalid because of inset == 0?
if (!slices_[i].isValid()) {
-   pop_back();
+   slices_.resize(i);
fixed = true;
+   break;
}
-   // The top level CursorSlice should always be valid.
-   BOOST_ASSERT(slices_[0].isValid());
-
-   if (idx() > lastidx()) {
-   lyxerr << "wrong idx " << idx()
-   << ", max is " << lastidx()
-   << " at level " << depth()
-   << ". Trying to correct this."  << endl;
-   lyxerr << "old: " << *this << endl;
-   for (size_t i = idx(); i != lastidx(); --i)
-   pop_back();
-   idx() = lastidx();
-   pit() = lastpit();
-   pos() = lastpos();
-   fixed = true;
-   }
-   else if (pit() > lastpit()) {
-   lyxerr << "wrong pit " << pit()
-   << ", max is " << lastpit()
-   << " at level " << depth()
-   << ". Trying to correct this."  << endl;
-   lyxerr << "old: " << *this << endl;
-   pit() = lastpit();
-   pos() = 0;
-   fixed = true;
-   }
-   else if (pos() > lastpos()) {
-   lyxerr << "wrong pos " << pos()
-   << ", max is " << lastpos()
-   << " at level " << depth()
-   << ". Trying to correct this."  << endl;
-   lyxerr << "old: " << *this << endl;
-   pos() = lastpos();
-   fixed = true;
+   if (slices_[i].idx() > slices_[i].lastidx()) {
+   lyxerr << "wrong idx " << slices_[i].idx()
+   << ", max is " << slices_[i].lastidx()
+   << " at level " << i
+   << ". Trying to correct this."  << endl;
+   lyxerr << "old: " << *this << endl;
+   // put in last index and position
+   slices_.resize(i + 1);
+   slices_[i].idx() = lastidx();
+   slices_[i].pit() = lastpit();
+   slices_[i].pos() = lastpos();
+   fixed = true;
+   break;
+   }
+   else if (!slices_[i].inset().inMathed() &&
+slices_[i].text() &&
+		 slices_[i].pit() > slices_[i].text()->paragraphs().size()  
- 1) {

+   pit_type lastpit = 
slices_[i].text()->paragraphs().size() - 1;
+   lyxerr << "wrong pit " << slices_[i].pit()
+   << ", max is " << lastpit
+   << " at level " << i
+   << ". Trying to correct this."  << endl;
+   lyxerr << "old: " << *this << endl;
+   slices_.resize(i + 1);
+   slices_[i].pit() = lastpit;
+   slices_[i].pos() = 0;
+   fixed = true;
+   break;
+   }
+   else if (slices_[i].pos() > slices_[i].lastpos()) {
+   lyxerr << "wrong pos " << slices_[i].pos()
+   << ", max is " << slices_[i].lastpos()
+   << " at level " << i
+   << ". Trying to correct this."  << endl;
+   lyxerr << "old: " << *this << endl;
+   slices_.resize(i + 1);
+   slices_[i].pos() = slices_[i].lastpos();
+   fixed = true;
+   break;
+   }
}
if (fixed) {
lyxerr << "new: " << *this << endl;





PGP.sig
Description: Signierter Teil der Nachricht


Re: [patch] LyX crashes with multiple views, #3785

2007-06-08 Thread Alfredo Braunstein
Stefan Schimanski wrote:

> If we want multiple views and update the cursors when switching, we
> should do it properly, maybe somehow similar to the patch below.
> 
> The bug: http://bugzilla.lyx.org/show_bug.cgi?id=3785
> 
> Stefan

Or... just apply 

http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg119336.html

;-)

A/





Re: [patch] LyX crashes with multiple views, #3785

2007-06-08 Thread Stefan Schimanski


Am 08.06.2007 um 20:05 schrieb Alfredo Braunstein:


Stefan Schimanski wrote:


If we want multiple views and update the cursors when switching, we
should do it properly, maybe somehow similar to the patch below.

The bug: http://bugzilla.lyx.org/show_bug.cgi?id=3785

Stefan


Or... just apply

http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg119336.html

;-)


Grrr, it would be helpful if one puts a comment at a bug if one has a  
patch. The subject of that thread is not really indicating that is  
has something to do with the bug.


Stefan


PGP.sig
Description: Signierter Teil der Nachricht


Re: [patch] LyX crashes with multiple views, #3785

2007-06-08 Thread Alfredo Braunstein
Stefan Schimanski wrote:

> Grrr, it would be helpful if one puts a comment at a bug if one has a
> patch. The subject of that thread is not really indicating that is
> has something to do with the bug.

Yes, sorry about that... I was hoping for the patch to be applied sooner, as
it was discussed enough, fixed a crash, and had some good side effects
(removal of the destroyed signals etc)...

A/




Re: [patch] LyX crashes with multiple views, #3785

2007-06-08 Thread Jürgen Spitzmüller
Alfredo Braunstein wrote:
>  I was hoping for the patch to be applied sooner, as
> it was discussed enough, fixed a crash, and had some good side effects
> (removal of the destroyed signals etc)...

But you wrote it's "completely untested". If this is no more true, I'd say go 
ahead and apply it.

Jürgen


Re: [patch] LyX crashes with multiple views, #3785

2007-06-09 Thread Alfredo Braunstein
Jürgen Spitzmüller wrote:

> Alfredo Braunstein wrote:
>>  I was hoping for the patch to be applied sooner, as
>> it was discussed enough, fixed a crash, and had some good side effects
>> (removal of the destroyed signals etc)...
> 
> But you wrote it's "completely untested". If this is no more true, I'd say
> go ahead and apply it.

I tested it a few days without problems. I don't have svn rights ATM, could
someone else do it for me? Last version is in the 'road to rc2' thread.

A/




Re: [patch] LyX crashes with multiple views, #3785

2007-06-09 Thread Jürgen Spitzmüller
Alfredo Braunstein wrote:
> I tested it a few days without problems. I don't have svn rights ATM, 

you should get them back as soon as possible IMHO. Then you're indebted to 
contribute again ;-)

> could someone else do it for me? Last version is in the 'road to rc2' 
> thread. 

I'll do it.

Jürgen


Re: [patch] LyX crashes with multiple views, #3785

2007-06-09 Thread Jürgen Spitzmüller
Am Samstag, 9. Juni 2007 schrieb Jürgen Spitzmüller:
> > could someone else do it for me? Last version is in the 'road to rc2'
> > thread.
>
> I'll do it.

But please write a log message.

Jürgen


Re: [patch] LyX crashes with multiple views, #3785

2007-06-09 Thread Stefan Schimanski


Am 09.06.2007 um 11:07 schrieb Jürgen Spitzmüller:


Alfredo Braunstein wrote:

I tested it a few days without problems. I don't have svn rights ATM,


you should get them back as soon as possible IMHO. Then you're  
indebted to

contribute again ;-)


could someone else do it for me? Last version is in the 'road to rc2'
thread.


I'll do it.


Please read my comment in the rc2 thread.

Stefan

PGP.sig
Description: Signierter Teil der Nachricht


Re: [patch] LyX crashes with multiple views, #3785

2007-06-09 Thread Stefan Schimanski
And, if the inset = 0 it's a broken cursor in any way, no? So take  
a wrong idx, hence  inset=0. In the next loop with inset()==inset  
will not cut if off. I think it's wrong.


I was right. You can crash it like this: "abcde", insert ERT inset,  
type inside "fgh". Place the cursor behind the h. Create a new  
window, select the everything and delete (even less is enough) =>  
crash because nargs is called on a 0 inset.


Stefan



PGP.sig
Description: Signierter Teil der Nachricht