-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash when rendering with SVG based symbols and SVG cache is filled
When the svg cache was full, any attempt to render an svg from the cache would crash QGIS. Fixes #16643
- Loading branch information
1 parent
b3ef4da
commit 942f431
Showing
4 changed files
with
161 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*************************************************************************** | ||
testqgssvgcache.cpp | ||
-------------------- | ||
Date : October 2017 | ||
Copyright : (C) 2017 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgstest.h" | ||
#include <QObject> | ||
#include <QString> | ||
#include <QStringList> | ||
#include <QApplication> | ||
#include <QFileInfo> | ||
#include <QDir> | ||
#include <QDesktopServices> | ||
|
||
#include "qgssvgcache.h" | ||
|
||
/** | ||
* \ingroup UnitTests | ||
* This is a unit test for QgsSvgCache. | ||
*/ | ||
class TestQgsSvgCache : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
TestQgsSvgCache() = default; | ||
|
||
private slots: | ||
void initTestCase();// will be called before the first testfunction is executed. | ||
void cleanupTestCase();// will be called after the last testfunction was executed. | ||
void init() {} // will be called before each testfunction is executed. | ||
void cleanup() {} // will be called after every testfunction. | ||
void fillCache(); | ||
|
||
}; | ||
|
||
|
||
void TestQgsSvgCache::initTestCase() | ||
{ | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
} | ||
|
||
void TestQgsSvgCache::cleanupTestCase() | ||
{ | ||
} | ||
|
||
void TestQgsSvgCache::fillCache() | ||
{ | ||
QgsSvgCache cache; | ||
// flood cache to fill it | ||
QString svgPath = TEST_DATA_DIR + QStringLiteral( "/sample_svg.svg" ); | ||
bool fitInCache = false; | ||
|
||
// we loop forever, continually increasing the size of the requested | ||
// svg render. The continually changing image size should quickly fill | ||
// the svg cache size, forcing use of non-cached images. | ||
// We break after hitting a certain threshold of non-cached images, | ||
// (after testing that the result is non-null, i.e. rendered on demand, | ||
// not from cache). | ||
int uncached = 0; | ||
for ( double size = 1000; uncached < 10; size += 100 ) | ||
{ | ||
QImage image = cache.svgAsImage( svgPath, size, QColor( 255, 0, 0 ), QColor( 0, 255, 0 ), 1, 1, fitInCache ); | ||
QVERIFY( !image.isNull() ); | ||
if ( !fitInCache ) | ||
uncached++; | ||
} | ||
} | ||
|
||
|
||
QGSTEST_MAIN( TestQgsSvgCache ) | ||
#include "testqgssvgcache.moc" |