Skip to content

Commit 32606e0

Browse files
author
rblazek
committed
fixed ticket #367, crash if a layer was removed whose topo had been deleted
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6066 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c34c6f6 commit 32606e0

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/providers/grass/qgsgrassprovider.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ void QgsGrassProvider::update ( void )
206206
#endif
207207

208208
mValid = false;
209-
// TODO check if reopened map is valid
209+
210+
if ( ! mMaps[mLayers[mLayerId].mapId].valid ) return;
210211

211212
// Getting the total number of features in the layer
212213
// It may happen that the field disappeares from the map (deleted features, new map without that field)
@@ -289,7 +290,7 @@ QgsFeature *QgsGrassProvider::getFirstFeature(bool fetchAttributes)
289290
std::cout << "QgsGrassProvider::getFirstFeature()" << std::endl;
290291
#endif
291292

292-
if ( isEdited() || isFrozen() )
293+
if ( isEdited() || isFrozen() || !mValid )
293294
return 0;
294295

295296
if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -309,7 +310,7 @@ bool QgsGrassProvider::getNextFeature(QgsFeature &feature, bool fetchAttributes)
309310
std::cout << "QgsGrassProvider::getNextFeature()" << std::endl;
310311
#endif
311312

312-
if ( isEdited() || isFrozen() )
313+
if ( isEdited() || isFrozen() || !mValid )
313314
return 0;
314315

315316
if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -330,7 +331,7 @@ QgsFeature *QgsGrassProvider::getNextFeature(bool fetchAttributes)
330331
<< " fetchAttributes = " << fetchAttributes << std::endl;
331332
#endif
332333

333-
if ( isEdited() || isFrozen() )
334+
if ( isEdited() || isFrozen() || !mValid )
334335
return 0;
335336

336337
if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -357,7 +358,7 @@ QgsFeature* QgsGrassProvider::getNextFeature(std::list<int> const& attlist, int
357358
std::cout << "QgsGrassProvider::getNextFeature( attlist )" << std::endl;
358359
#endif
359360

360-
if ( isEdited() || isFrozen() )
361+
if ( isEdited() || isFrozen() || !mValid )
361362
return 0;
362363

363364
if ( mCidxFieldIndex < 0 ) return 0; // No features, no features in this layer
@@ -471,6 +472,7 @@ void QgsGrassProvider::resetSelection( bool sel)
471472
#ifdef QGISDEBUG
472473
std::cout << "QgsGrassProvider::resetSelection()" << std::endl;
473474
#endif
475+
if ( !mValid ) return;
474476
memset ( mSelection, (int) sel, mSelectionSize );
475477
mNextCidx = 0;
476478
}
@@ -486,7 +488,7 @@ void QgsGrassProvider::select(QgsRect *rect, bool useIntersect)
486488
std::cout << "QgsGrassProvider::select() useIntersect = " << useIntersect << std::endl;
487489
#endif
488490

489-
if ( isEdited() || isFrozen() )
491+
if ( isEdited() || isFrozen() || !mValid )
490492
return;
491493

492494
// check if outdated and update if necessary
@@ -560,7 +562,7 @@ std::vector<QgsFeature>& QgsGrassProvider::identify(QgsRect * rect)
560562

561563
// TODO: does not return vector of features! Should it?
562564

563-
if ( !isEdited() && !isFrozen() ) {
565+
if ( !isEdited() && !isFrozen() && mValid ) {
564566
select(rect, true);
565567
}
566568
}
@@ -614,7 +616,7 @@ int QgsGrassProvider::keyField()
614616

615617
void QgsGrassProvider::reset()
616618
{
617-
if ( isEdited() || isFrozen() )
619+
if ( isEdited() || isFrozen() || !mValid )
618620
return;
619621

620622
int mapId = mLayers[mLayerId].mapId;
@@ -757,6 +759,10 @@ void QgsGrassProvider::loadAttributes ( GLAYER &layer )
757759
std::cerr << "QgsGrassProvider::loadLayerSourcesFromMap" << std::endl;
758760
#endif
759761

762+
// TODO: free old attributes
763+
764+
if ( !layer.map ) return;
765+
760766
// Get field info
761767
layer.fieldInfo = Vect_get_field( layer.map, layer.field); // should work also with field = 0
762768

@@ -1116,6 +1122,7 @@ void QgsGrassProvider::updateMap ( int mapId )
11161122
/* Close map */
11171123
GMAP *map = &(mMaps[mapId]);
11181124

1125+
bool closeMap = map->valid;
11191126
map->valid = false;
11201127
map->version++;
11211128

@@ -1125,7 +1132,7 @@ void QgsGrassProvider::updateMap ( int mapId )
11251132
// TODO: Is it necessary for close ?
11261133
G__setenv( "MAPSET", (char *) map->mapset.ascii() );
11271134

1128-
Vect_close ( map->map );
1135+
if ( closeMap ) Vect_close ( map->map );
11291136

11301137
QFileInfo di ( map->gisdbase + "/" + map->location + "/" + map->mapset + "/vector/" + map->mapName );
11311138
map->lastModified = di.lastModified();
@@ -1180,8 +1187,11 @@ void QgsGrassProvider::closeMap( int mapId )
11801187
"you can expect crash soon." );
11811188
}
11821189

1190+
if ( mMaps[mapId].valid )
1191+
{
1192+
Vect_close ( mMaps[mapId].map );
1193+
}
11831194
mMaps[mapId].valid = false;
1184-
Vect_close ( mMaps[mapId].map );
11851195
}
11861196
}
11871197

0 commit comments

Comments
 (0)