Skip to content

Commit

Permalink
Fix #10271 (crash from race condition in SVG cache when using paralle…
Browse files Browse the repository at this point in the history
…l rendering)
  • Loading branch information
wonder-sk committed Jun 15, 2014
1 parent 9d8a842 commit f3ff3b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgssvgcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ QgsSvgCache::~QgsSvgCache()
const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache )
{
QMutexLocker locker( &mMutex );

fitsInCache = true;
QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );

Expand Down Expand Up @@ -152,6 +154,8 @@ const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const Q
const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput )
{
QMutexLocker locker( &mMutex );

QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );

//if current entry picture is 0: cache picture for entry
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology-ng/qgssvgcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QColor>
#include <QMap>
#include <QMultiHash>
#include <QMutex>
#include <QString>
#include <QUrl>

Expand Down Expand Up @@ -176,6 +177,9 @@ class CORE_EXPORT QgsSvgCache : public QObject

/** SVG content to be rendered if SVG file was not found. */
QByteArray mMissingSvg;

//! Mutex to prevent concurrent access to the class from multiple threads at once (may corrupt the entries otherwise).
QMutex mMutex;
};

#endif // QGSSVGCACHE_H

0 comments on commit f3ff3b4

Please sign in to comment.