Skip to content

Commit 3865ccd

Browse files
wonder-skjef-n
authored andcommitted
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)
1 parent b0e7e70 commit 3865ccd

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

python/core/symbology-ng/qgssvgcache.sip

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ class QgsSvgCacheEntry
1414
* @param rasterScaleFactor raster scale factor
1515
* @param fill color of fill
1616
* @param outline color of outline
17+
* @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
1718
*/
18-
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline );
19+
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
1920
~QgsSvgCacheEntry();
2021

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

src/core/symbology-ng/qgssvgcache.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ QgsSvgCacheEntry::QgsSvgCacheEntry()
5151
{
5252
}
5353

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

200-
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline );
201+
QgsSvgCacheEntry* entry = new QgsSvgCacheEntry( path, size, outlineWidth, widthScaleFactor, rasterScaleFactor, fill, outline, file );
201202

202203
replaceParamsAndCacheSvg( entry );
203204

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

726727
takeEntryFromList( bkEntry );
727-
mEntryLookup.remove( bkEntry->file, bkEntry );
728+
mEntryLookup.remove( bkEntry->lookupKey, bkEntry );
728729
mTotalSize -= bkEntry->dataSize();
729730
delete bkEntry;
730731
}

src/core/symbology-ng/qgssvgcache.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ class CORE_EXPORT QgsSvgCacheEntry
4141
* @param rasterScaleFactor raster scale factor
4242
* @param fill color of fill
4343
* @param outline color of outline
44+
* @param lookupKey the key string used in QgsSvgCache for quick lookup of this entry (relative or absolute path)
4445
*/
45-
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline );
46+
QgsSvgCacheEntry( const QString& file, double size, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, const QColor& fill, const QColor& outline, const QString& lookupKey = QString() );
4647
~QgsSvgCacheEntry();
4748

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

0 commit comments

Comments
 (0)