Skip to content

Commit

Permalink
Fix GPX provider crashes if feature count is called on an invalid layer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 30, 2021
1 parent f5e0222 commit 18813d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/vector/qgsvectorlayer.cpp
Expand Up @@ -3428,8 +3428,8 @@ QgsAttributeList QgsVectorLayer::primaryKeyAttributes() const

long long QgsVectorLayer::featureCount() const
{
if ( ! mDataProvider )
return -1;
if ( !mDataProvider )
return static_cast< long long >( Qgis::FeatureCountState::UnknownCount );
return mDataProvider->featureCount() +
( mEditBuffer && ! mDataProvider->transaction() ? mEditBuffer->addedFeatures().size() - mEditBuffer->deletedFeatureIds().size() : 0 );
}
Expand Down
3 changes: 3 additions & 0 deletions src/providers/gpx/qgsgpxprovider.cpp
Expand Up @@ -158,6 +158,9 @@ QgsWkbTypes::Type QgsGPXProvider::wkbType() const
*/
long long QgsGPXProvider::featureCount() const
{
if ( !data )
return static_cast< long long >( Qgis::FeatureCountState::UnknownCount );

if ( mFeatureType == WaypointType )
return data->getNumberOfWaypoints();
if ( mFeatureType == RouteType )
Expand Down

0 comments on commit 18813d2

Please sign in to comment.