On Wed, May 16, 2018 at 10:01:16AM +0200, Jean-Marc Lasgouttes wrote:
> Le 15/05/2018 à 19:51, Enrico Forestieri a écrit :
> > > The problem seems to be in the calling code. This seems to happen for svgz
> > > files (compressed svg files).
> > 
> > Actually, it seems to happen when the same image is included multiple
> > times, irrespective of the type. See attached example.
> > 
> > Bisect leads to a31d3dc6 as the commit that introduced this issue.
> 
> I tried to figure out what happens, but this graphics preview code is a
> nightmare to me. Is there someone who can tell me how it works?

I don't know that code, so what follows is pure speculation. I think that
the preview machinery is activated during the metrics calculation. When
an image has to be loaded a second time, its preview is going to be
regenerated again, if the cache is not used or if it is not in the cache.
In order to do so, most variables are reset, among which also the target
format. Now, when the same image appears more than one time on screen,
while the first instance is being converted, a request for the second
instance is issued, because the image is not in the cache still or the
cache is not used. Hence, the same variables that are being used for the
preview of the first instance are now cleared while the conversion is
still not finished. Bummer.

I think that a31d3dc6 simply exposed this bug by increasing the frequency
of the metrics computation. The attached patch simply avoids clearing the
above variables when a conversion in progress is detected. It works for
me for the test case posted in this thread but I don't know whether it
is the right thing to do.

-- 
Enrico
diff --git a/src/graphics/GraphicsCacheItem.cpp 
b/src/graphics/GraphicsCacheItem.cpp
index f54ce80ec3..9ac96d4c9a 100644
--- a/src/graphics/GraphicsCacheItem.cpp
+++ b/src/graphics/GraphicsCacheItem.cpp
@@ -145,13 +145,13 @@ FileName const & CacheItem::filename() const
 
 bool CacheItem::tryDisplayFormat() const
 {
-       if (pimpl_->status_ != WaitingToLoad)
+       if (pimpl_->status_ != WaitingToLoad && pimpl_->status_ != Converting)
                pimpl_->reset();
        FileName filename;
        string from;
        bool const conversion_needed = pimpl_->tryDisplayFormat(filename, from);
        bool const success = status() == Loaded && !conversion_needed;
-       if (!success)
+       if (!success && pimpl_->status_ != Converting)
                pimpl_->reset();
        return success;
 }

Reply via email to