commit 2973108a62c893981568c7cbc6ac3bd4db3a92f1
Author: Enrico Forestieri <for...@lyx.org>
Date:   Sun Jun 21 11:21:59 2015 +0200

    Make really sure to wait for previews after zoom changes
    
    Relying on the fact that the timer is not active anymore does not
    guarantee that the previews at the correct zoom are ready because
    the regeneration process may take several seconds and during this
    time the zoom factor may be changed again. So, we need an additional
    guard for assuring that everything has settled down.

diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index ea8e3ce..7a96976 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -254,6 +254,8 @@ private:
        mutable int font_scaling_factor_;
        ///
        QTimer * delay_refresh_;
+       ///
+       bool finished_generating_;
 
        /// We don't own this
        static lyx::Converter const * pconverter_;
@@ -402,7 +404,7 @@ namespace lyx {
 namespace graphics {
 
 PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
-       : parent_(p), buffer_(b)
+       : parent_(p), buffer_(b), finished_generating_(true)
 {
        font_scaling_factor_ = int(buffer_.fontScalingFactor());
        if (!pconverter_)
@@ -437,8 +439,8 @@ PreviewLoader::Impl::preview(string const & latex_snippet) 
const
                // has not been changed for about 1 second.
                delay_refresh_->start(1000);
        }
-       // Don't try to access the cache until we are finished.
-       if (delay_refresh_->isActive())
+       // Don't try to access the cache until we are done.
+       if (delay_refresh_->isActive() || !finished_generating_)
                return 0;
        Cache::const_iterator it = cache_.find(latex_snippet);
        return (it == cache_.end()) ? 0 : it->second.get();
@@ -452,6 +454,7 @@ void PreviewLoader::Impl::refreshPreviews()
        Cache::const_iterator cend = cache_.end();
        while (cit != cend)
                parent_.remove((cit++)->first);
+       finished_generating_ = false;
        buffer_.updatePreviews();
 }
 
@@ -788,6 +791,7 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int 
retval)
        for (; nit != nend; ++nit) {
                imageReady(*nit->get());
        }
+       finished_generating_ = true;
 }
 
 

Reply via email to