Re: Field bugs was Re: commit: undebugged Lists and Fields.

Subject: Re: Field bugs was Re: commit: undebugged Lists and Fields.
From: Martin Sevior (
Date: Wed Nov 08 2000 - 21:26:19 CST

On Wed, 8 Nov 2000, Sam TH wrote:
> Ha - I win. The following patch fixes the problem for me.
> As it turns out, the problem was much worse than it appeared. Just
> try opening a new document, and hitting the left arrow key. Instant
> segfault. This fixes that, and the undo of fields at the beginning
> of the document, and I think a bunch of other problems. Detailed
> explanation after the patch.

Glad I was starting on this then :-)

> Patch:
> diff -u -r1.307 fv_View.cpp
> --- src/text//fmt/xp/fv_View.cpp 2000/11/09 01:00:57 1.307
> +++ src/text//fmt/xp/fv_View.cpp 2000/11/09 02:59:46
> @@ -4567,6 +4567,9 @@
> UT_sint32 iPointHeight;
> fl_BlockLayout* pBlock = _findBlockAtPosition(pos);
> + while(!pBlock)
> + pBlock = _findBlockAtPosition((PT_DocPosition) pos++);
> +
> UT_ASSERT(pBlock);
> fp_Run* pRun = pBlock->findPointCoords(pos, bEOL, xPoint, yPoint, iPointHeight);
> Explanation:
> The problem was, we were asking for the Block in the document at or before
> pos. However, if pos == 1, then there was no block that fit these
> criteria. Then, when you try to use pBlock about at the bottom of the patch
> there, it segfaults. In order to fix this, I just said that if we don't
> find the block there, we keep going through the document until we find
> one.
> This could have been done deeper in the call chain resulting from
> _findBlockAtPosition(), but this was where the syntax was easiest.
> As this isn't really the answer we want in the case that we have to
> use the while loop, this may introduce bugs. Therefore, I haven't
> committed it yet. If people think that it's not a good idea, I'll
> hold off, but this issue has to be fixed before 0.7.12 goes out.

Yes there is a potential problem if pos runs past the end of the document.
You might want a call to m_pDoc->getbounds() before/in the loop to make
sure pos is sane. You use the code like this

        PT_DocPosition posBOD;
        PT_DocPosition posEOD;
        UT_Bool bRes;

        bRes = m_pDoc->getBounds(UT_FALSE, posBOD);
        bRes = m_pDoc->getBounds(UT_TRUE, posEOD);
I'll leave the details for you... (handwave, handwave)



This archive was generated by hypermail 2b25 : Wed Nov 08 2000 - 21:26:30 CST