Skip to content
Permalink
Browse files
Fix crashes when rendering with SVG symbols that are missing
The crashes would happen after some time when browsing the map,
especially when size of SVGs is in map units. This was due to wrong
removal of deleted cache entries where cache entry key would be
different from SVG file's path, thus not removing the entry that
got deleted. Now explicitly keeping the lookup key in the entry
to make sure this does not happen.

Related issues: #9959, #8883

(cherry picked from commit febadfe)
  • Loading branch information
wonder-sk authored and jef-n committed Jul 31, 2015
1 parent b0e7e70 commit 3865ccdced3ecd855b03842ca30602bc204a6758
@@ -14,11 +14,15 @@ class QgsSvgCacheEntry
* @param rasterScaleFactor raster scale factor
* @param fill color of fill
* @param outline color of outline
* @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
*/
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline );
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
~QgsSvgCacheEntry();

//! Absolute path to SVG file
QString file;
//! Lookup key used by QgsSvgCache's hashtable (relative or absolute path). Needed for removal from the hashtable
QString lookupKey;
double size; //size in pixels (cast to int for QImage)
double outlineWidth;
double widthScaleFactor;
@@ -51,8 +51,9 @@ QgsSvgCacheEntry::QgsSvgCacheEntry()
{
}

QgsSvgCacheEntry::QgsSvgCacheEntry( const QString& f, double s, double ow, double wsf, double rsf, const QColor& fi, const QColor& ou )
QgsSvgCacheEntry::QgsSvgCacheEntry( const QString& f, double s, double ow, double wsf, double rsf, const QColor& fi, const QColor& ou, const QString& lk )
: file( f )
, lookupKey( lk.isEmpty() ? f : lk )
, size( s )
, outlineWidth( ow )
, widthScaleFactor( wsf )
@@ -197,7 +198,7 @@ QgsSvgCacheEntry* QgsSvgCache::insertSVG( const QString& file, double size, cons
// The file may be relative path (e.g. if path is data defined)
QString path = QgsSymbolLayerV2Utils::symbolNameToPath( file );

QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline, file );

replaceParamsAndCacheSvg( entry );

@@ -724,7 +725,7 @@ void QgsSvgCache::trimToMaximumSize()
entry = entry->nextEntry;

takeEntryFromList( bkEntry );
mEntryLookup.remove( bkEntry->file, bkEntry );
mEntryLookup.remove( bkEntry->lookupKey, bkEntry );
mTotalSize -= bkEntry->dataSize();
delete bkEntry;
}
@@ -41,11 +41,15 @@ class CORE_EXPORT QgsSvgCacheEntry
* @param rasterScaleFactor raster scale factor
* @param fill color of fill
* @param outline color of outline
* @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
*/
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline );
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
~QgsSvgCacheEntry();

//! Absolute path to SVG file
QString file;
//! Lookup key used by QgsSvgCache's hashtable (relative or absolute path). Needed for removal from the hashtable
QString lookupKey;
double size; //size in pixels (cast to int for QImage)
double outlineWidth;
double widthScaleFactor;

0 comments on commit 3865ccd

Please sign in to comment.