Skip to content

Commit

Permalink
fix bad alloc when mesh's arrows of 3D rendering has too small spacing (
Browse files Browse the repository at this point in the history
#37195)

* fix bad alloc when mesh's arrows of 3D rendering has too small spacing

* Update src/core/mesh/qgsmeshlayerutils.cpp

Co-authored-by: Harrissou Sant-anna <delazj@gmail.com>

* fix mesh terrain not rendering anymore

Co-authored-by: Harrissou Sant-anna <delazj@gmail.com>
  • Loading branch information
vcloarec and DelazJ committed Jun 16, 2020
1 parent 659ed39 commit 76946dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/3d/mesh/qgsmesh3dmaterial_p.cpp
Expand Up @@ -366,6 +366,9 @@ void QgsMesh3dMaterial::configureArrows( QgsMeshLayer *layer, const QgsDateTimeR
ySpacing, ySpacing,
gridSize, gridSize,
minCorner ); minCorner );

if ( vectors.isEmpty() )
return;
} }


mTechnique->addParameter( arrowsEnabledParameter ) ; mTechnique->addParameter( arrowsEnabledParameter ) ;
Expand Down
3 changes: 2 additions & 1 deletion src/3d/symbols/qgsmesh3dsymbol.cpp
Expand Up @@ -93,7 +93,8 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() ); mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() );
mSingleColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) ); mSingleColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) );
mArrowsEnabled = elemAdvancedSettings.attribute( QStringLiteral( "arrows-enabled" ) ).toInt(); mArrowsEnabled = elemAdvancedSettings.attribute( QStringLiteral( "arrows-enabled" ) ).toInt();
mArrowsSpacing = elemAdvancedSettings.attribute( QStringLiteral( "arrows-spacing" ) ).toDouble(); if ( elemAdvancedSettings.hasAttribute( QStringLiteral( "arrows-spacing" ) ) )
mArrowsSpacing = elemAdvancedSettings.attribute( QStringLiteral( "arrows-spacing" ) ).toDouble();
mArrowsFixedSize = elemAdvancedSettings.attribute( QStringLiteral( "arrows-fixed-size" ) ).toInt(); mArrowsFixedSize = elemAdvancedSettings.attribute( QStringLiteral( "arrows-fixed-size" ) ).toInt();
QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) ); QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
if ( !elemDDP.isNull() ) if ( !elemDDP.isNull() )
Expand Down
12 changes: 11 additions & 1 deletion src/core/mesh/qgsmeshlayerutils.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgsmeshlayerutils.h" #include "qgsmeshlayerutils.h"
#include "qgsmeshtimesettings.h" #include "qgsmeshtimesettings.h"
#include "qgstriangularmesh.h" #include "qgstriangularmesh.h"
#include "qgslogger.h"
#include "qgsmeshdataprovider.h" #include "qgsmeshdataprovider.h"
#include "qgsmesh3daveraging.h" #include "qgsmesh3daveraging.h"
#include "qgsmeshlayer.h" #include "qgsmeshlayer.h"
Expand Down Expand Up @@ -129,7 +130,16 @@ QVector<QgsVector> QgsMeshLayerUtils::griddedVectorValues( const QgsMeshLayer *m
if ( dataType == QgsMeshDatasetGroupMetadata::DataOnEdges ) if ( dataType == QgsMeshDatasetGroupMetadata::DataOnEdges )
return vectors; return vectors;


vectors.reserve( size.height()*size.width() ); try
{
vectors.reserve( size.height()*size.width() );
}
catch ( ... )
{
QgsDebugMsgLevel( "Unable to store the arrow grid in memory", 1 );
return QVector<QgsVector>();
}

for ( int iy = 0; iy < size.height(); ++iy ) for ( int iy = 0; iy < size.height(); ++iy )
{ {
double y = minCorner.y() + iy * ySpacing; double y = minCorner.y() + iy * ySpacing;
Expand Down

0 comments on commit 76946dd

Please sign in to comment.