Skip to content

Commit f3ff3b4

Browse files
committedJun 15, 2014
Fix #10271 (crash from race condition in SVG cache when using parallel rendering)
1 parent 9d8a842 commit f3ff3b4

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎src/core/symbology-ng/qgssvgcache.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ QgsSvgCache::~QgsSvgCache()
109109
const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
110110
double widthScaleFactor, double rasterScaleFactor, bool& fitsInCache )
111111
{
112+
QMutexLocker locker( &mMutex );
113+
112114
fitsInCache = true;
113115
QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
114116

@@ -152,6 +154,8 @@ const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const Q
152154
const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth,
153155
double widthScaleFactor, double rasterScaleFactor, bool forceVectorOutput )
154156
{
157+
QMutexLocker locker( &mMutex );
158+
155159
QgsSvgCacheEntry* currentEntry = cacheEntry( file, size, fill, outline, outlineWidth, widthScaleFactor, rasterScaleFactor );
156160

157161
//if current entry picture is 0: cache picture for entry

‎src/core/symbology-ng/qgssvgcache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QColor>
2222
#include <QMap>
2323
#include <QMultiHash>
24+
#include <QMutex>
2425
#include <QString>
2526
#include <QUrl>
2627

@@ -176,6 +177,9 @@ class CORE_EXPORT QgsSvgCache : public QObject
176177

177178
/** SVG content to be rendered if SVG file was not found. */
178179
QByteArray mMissingSvg;
180+
181+
//! Mutex to prevent concurrent access to the class from multiple threads at once (may corrupt the entries otherwise).
182+
QMutex mMutex;
179183
};
180184

181185
#endif // QGSSVGCACHE_H

0 commit comments

Comments
 (0)
Please sign in to comment.