On 30-Apr-2002 Claus Hindsgaul wrote:
> Sorry, no luck with the new patch

Ok thanks for the file I can recreate the crash with it and your explanation.
I fixed this now hopefully but there is IMO a greater problem to fix in GCItem.

(this is for Angus)
IMO that this function is wrong:

void GCacheItem::setStatus(ImageStatus new_status)
{
[snip]
                        // Use of current_view is very, very Evil!!
                        current_view->updateInset(inset, false);
[snip]
}

IMO we shouldn't call a updateInset() here we should set a flag in the
owning inset and let the inset decide when to call the updateInset call.
Why did the above crash, because inside the inset draw() function we
called ::startLoading which called ::setStatus() which called an update
and which called a ::drawInset() again. This is somehow wrong IMO.

I think you should use the ::update() call of the InsetGraphic to do this
type of stuff and not do it inside the draw() routine. Hmm but that wouldn't
change a lot. IMO we should rework all this udpate and rebreak stuff in 1.3.0.

This is maybe a work for the developers-meeting where we have enough mind-power
(givven that we have enough energy supply ;) to discuss and reimplement this.

So see this only as a general comment and as a reminder for all of us ;)

To Claus:

Please apply the attached patch to a fresh checkout or in alternative you
could just 'rm src/screen.c src/text.C src/lyxtext.h;cvs update' and then
apply the patch. It solves the problem for me.

         Jug

--
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._
Dr. Jürgen Vigna        E-Mail:  [EMAIL PROTECTED]
Italienallee 13/N       Tel/Fax: +39-0471-450260 / +39-0471-450253
I-39100 Bozen           Web:     http://www.sad.it/~jug
-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._-._

There is always someone worse off than yourself.

Index: src/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.244
diff -u -p -r1.244 text.C
--- src/text.C  24 Apr 2002 15:37:16 -0000      1.244
+++ src/text.C  2 May 2002 09:43:14 -0000
@@ -475,23 +475,25 @@ void LyXText::drawNewline(DrawRowParams 
 }
 
 
-void LyXText::drawInset(DrawRowParams & p, pos_type const pos)
+bool LyXText::drawInset(DrawRowParams & p, pos_type const pos)
 {
        Inset * inset = p.row->par()->getInset(pos);
 
        // FIXME: shouldn't happen
        if (!inset) {
-               return;
+               return true;
        }
 
        LyXFont const & font = getFont(p.bv->buffer(), p.row->par(), pos);
+       // we need this here as the row pointer may be illegal
+       // at a later time (Jug20020502)
+       Row * prev = p.row->previous();
 
        inset->update(p.bv, font, false);
        inset->draw(p.bv, font, p.yo + p.row->baseline(), p.x, p.cleared);
 
        if (!need_break_row && !inset_owner
            && p.bv->text->status() == CHANGED_IN_DRAW) {
-               Row * prev = p.row->previous();
                if (prev && prev->par() == p.row->par()) {
                        breakAgainOneRow(p.bv, prev);
                        if (prev->next() != p.row) {
@@ -501,11 +503,15 @@ void LyXText::drawInset(DrawRowParams & 
                        } else {
                                need_break_row = p.row;
                        }
+               } else if (!prev) {
+                       need_break_row = firstrow;
                } else {
-                       need_break_row = p.row;
+                       need_break_row = prev->next();
                }
                setCursor(p.bv, cursor.par(), cursor.pos());
+               return false;
        }
+       return true;
 }
 
 
@@ -630,7 +636,7 @@ void LyXText::drawChars(DrawRowParams & 
 }
 
 
-void LyXText::draw(DrawRowParams & p, pos_type & vpos)
+bool LyXText::draw(DrawRowParams & p, pos_type & vpos)
 {
        pos_type const pos = vis2log(vpos);
        Paragraph * par = p.row->par();
@@ -644,12 +650,13 @@ void LyXText::draw(DrawRowParams & p, po
        if (IsNewlineChar(c)) {
                ++vpos;
                drawNewline(p, pos);
-               return;
+               return true;
        } else if (IsInsetChar(c)) {
-               drawInset(p, pos);
+               if (!drawInset(p, pos))
+                       return false;
                ++vpos;
                drawForeignMark(p, orig_x, orig_font);
-               return;
+               return true;
        }
 
        // usual characters, no insets
@@ -681,6 +688,7 @@ void LyXText::draw(DrawRowParams & p, po
                lyxerr << "No this shouldn't happen!\n";
 #endif
 #endif
+       return true;
 }
 
 
@@ -3662,7 +3670,8 @@ void LyXText::paintRowText(DrawRowParams
                                p.x += p.separator;
                        ++vpos;
                } else {
-                       draw(p, vpos);
+                       if (!draw(p, vpos))
+                               break;
                }
        }
 }
Index: src/lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.111
diff -u -p -r1.111 lyxtext.h
--- src/lyxtext.h       1 May 2002 22:17:05 -0000       1.111
+++ src/lyxtext.h       2 May 2002 09:43:15 -0000
@@ -648,11 +648,11 @@ private:
        /// draw a mark for foreign language, starting from orig_x
        void drawForeignMark(DrawRowParams & p, float const orig_x, LyXFont const & 
orig_font);
        /// draw an inset
-       void drawInset(DrawRowParams & p, lyx::pos_type const pos);
+       bool drawInset(DrawRowParams & p, lyx::pos_type const pos);
        /// draw new line marker
        void drawNewline(DrawRowParams & p, lyx::pos_type const pos);
        /// draw text
-       void draw(DrawRowParams & p, lyx::pos_type & vpos);
+       bool draw(DrawRowParams & p, lyx::pos_type & vpos);
 
        /// get the next breakpoint in a given paragraph
        lyx::pos_type nextBreakPoint(BufferView *, Row const * row, int width) const;
Index: src/screen.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/screen.C,v
retrieving revision 1.63
diff -u -p -r1.63 screen.C
--- src/screen.C        1 May 2002 22:17:06 -0000       1.63
+++ src/screen.C        2 May 2002 09:43:15 -0000
@@ -135,6 +135,11 @@ void LyXScreen::drawFromTo(LyXText * tex
                        text->setCursor(bv, text->cursor.par(),
                                        text->cursor.pos());
                        text->status(bv, st);
+                       // we should be sure our row-pointer is still valid, so it's
+                       // better to recompute it.
+                       y_text = y + text->first_y;
+                       row = text->getRowNearY(y_text);
+                       y = y_text - text->first_y;
                        text->getVisibleRow(bv, y + y_offset,
                                            x_offset, row, y + text->first_y);
                }
@@ -161,18 +166,7 @@ void LyXScreen::drawOneRow(LyXText * tex
        if (((y + row->height()) > 0) &&
            ((y - row->height()) <= static_cast<int>(owner.height()))) {
                // ok there is something visible
-#if 0
-               LyXText::text_status st = bv->text->status();
-               do {
-                       bv->text->status(bv, st);
-                       text->getVisibleRow(bv, y, x_offset, row,
-                                           y + text->first_y);
-               } while (!text->inset_owner &&
-                        text->status() == LyXText::CHANGED_IN_DRAW);
-               bv->text->status(bv, st);
-#else
                text->getVisibleRow(bv, y, x_offset, row, y + text->first_y);
-#endif
        }
        force_clear = false;
 }

Reply via email to