Skip to content

Commit

Permalink
Fix crashes when rendering with SVG symbols that are missing
Browse files Browse the repository at this point in the history
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 committed Jul 31, 2015
1 parent 1714e66 commit 6be19a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion python/core/symbology-ng/qgssvgcache.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/core/symbology-ng/qgssvgcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/symbology-ng/qgssvgcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6be19a8

Please sign in to comment.