From d6b1f4946f930b825371579fa9c84bfc591d73f3 Mon Sep 17 00:00:00 2001 From: Patrick Valsecchi Date: Tue, 1 May 2018 16:46:31 +0200 Subject: [PATCH] Fix crssync crash during build On my machine, crssync dies with a core dump during the build of QGIS. Infinite loop because there is no color defined in the scheme it loads. --- src/core/qgscolorschemeregistry.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/qgscolorschemeregistry.cpp b/src/core/qgscolorschemeregistry.cpp index 85a1874659c..d6ccf9551b0 100644 --- a/src/core/qgscolorschemeregistry.cpp +++ b/src/core/qgscolorschemeregistry.cpp @@ -117,12 +117,15 @@ void QgsColorSchemeRegistry::setRandomStyleColorScheme( QgsColorScheme *scheme ) { mRandomStyleColors = scheme->fetchColors(); - std::random_device rd; - std::mt19937 mt( rd() ); - std::uniform_int_distribution colorDist( 0, mRandomStyleColors.count() - 1 ); - mNextRandomStyleColorIndex = colorDist( mt ); - std::uniform_int_distribution colorDir( 0, 1 ); - mNextRandomStyleColorDirection = colorDir( mt ) == 0 ? -1 : 1; + if ( mRandomStyleColors.count() > 0 ) + { + std::random_device rd; + std::mt19937 mt( rd() ); + std::uniform_int_distribution colorDist( 0, mRandomStyleColors.count() - 1 ); + mNextRandomStyleColorIndex = colorDist( mt ); + std::uniform_int_distribution colorDir( 0, 1 ); + mNextRandomStyleColorDirection = colorDir( mt ) == 0 ? -1 : 1; + } } else {