* Clear the paragraph metrics cache as well on redraw:

On fullscreen redraw the metrics of all visible paragraphs are
  recreated and stored in the TextMetrics object. If the number of
  paragraphs on screen does not change everything is fine because the
  paragraph metrics cache is just updated. But if the number decreases
  it can happen that old paragraph metrics remain in the cache. If this
  happened because e.g. a paragraph was deleted, it's possible that the
  cached paragraph is longer than the one which is actually at the
  position now. Using the Row objects from the cached paragraphs then
  can trigger accesses to positions which would have been valid in the
  old paragraph, but go over the end of the paragraph which is there
  now. 


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18841 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2007-06-21 06:41:55 +00:00
parent 5286634d17
commit 557521034f
2 changed files with 11 additions and 4 deletions

View File

@ -1440,6 +1440,15 @@ void BufferView::updateMetrics(bool singlepar)
offset_ref_ = 0; offset_ref_ = 0;
} }
if (!singlepar) {
// Clear out the position cache in case of full screen redraw,
coord_cache_.clear();
// Clear out paragraph metrics to avoid having invalid metrics
// in the cache from paragraphs not relayouted below
tm.clear();
}
// If the paragraph metrics has changed, we can not // If the paragraph metrics has changed, we can not
// use the singlepar optimisation. // use the singlepar optimisation.
if (singlepar if (singlepar
@ -1459,10 +1468,6 @@ void BufferView::updateMetrics(bool singlepar)
if (!singlepar) if (!singlepar)
tm.redoParagraph(pit); tm.redoParagraph(pit);
// Clear out the position cache in case of full screen redraw.
if (!singlepar)
coord_cache_.clear();
int y0 = tm.parMetrics(pit).ascent() - offset_ref_; int y0 = tm.parMetrics(pit).ascent() - offset_ref_;
// Redo paragraphs above anchor if necessary. // Redo paragraphs above anchor if necessary.

View File

@ -48,6 +48,8 @@ public:
/// \retval true if a full screen redraw is needed. /// \retval true if a full screen redraw is needed.
/// \retval false if a single paragraph redraw is enough. /// \retval false if a single paragraph redraw is enough.
bool redoParagraph(pit_type const pit); bool redoParagraph(pit_type const pit);
/// Clear cache of paragraph metrics
void clear() { par_metrics_.clear(); }
/// ///
int ascent() const { return dim_.asc; } int ascent() const { return dim_.asc; }