@@ -1113,9 +1113,9 @@ QStringList QgsGrass::vectorLayers( const QString& gisdbase, const QString& loca
1113
1113
// Vect_set_open_level( 2 );
1114
1114
1115
1115
// TODO: We are currently using vectDestroyMapStruct in G_CATCH blocks because we know
1116
- // that it does cannot call another G_fatal_error, but once we switch to hypothetical Vect_destroy_map_struct
1116
+ // that it cannot call another G_fatal_error, but once we switch to hypothetical Vect_destroy_map_struct
1117
1117
// it should be verified if it can still be in G_CATCH
1118
- struct Map_info *map = vectNewMapStruct () ;
1118
+ struct Map_info *map = 0 ;
1119
1119
int level = -1 ;
1120
1120
1121
1121
// Vect_open_old_head GRASS is raising fatal error if topo exists but it is in different (older) version.
@@ -1124,6 +1124,7 @@ QStringList QgsGrass::vectorLayers( const QString& gisdbase, const QString& loca
1124
1124
1125
1125
G_TRY
1126
1126
{
1127
+ map = vectNewMapStruct ();
1127
1128
level = Vect_open_old_head ( map, ( char * ) mapName.toUtf8 ().data (), ( char * ) mapset.toUtf8 ().data () );
1128
1129
}
1129
1130
G_CATCH ( QgsGrass::Exception &e )
@@ -1647,24 +1648,44 @@ bool QgsGrass::mapRegion( QgsGrassObject::Type type, QString gisdbase,
1647
1648
}
1648
1649
catch ( QgsGrass::Exception &e )
1649
1650
{
1650
- QgsGrass:: warning ( e );
1651
+ warning ( e );
1651
1652
return false ;
1652
1653
}
1653
1654
1654
- struct Map_info Map;
1655
-
1656
- int level = Vect_open_old_head ( &Map,
1657
- map.toUtf8 ().data (), mapset.toUtf8 ().data () );
1655
+ struct Map_info *Map = 0 ;
1656
+ int level = -1 ;
1657
+ G_TRY
1658
+ {
1659
+ Map = vectNewMapStruct ();
1660
+ level = Vect_open_old_head ( Map, map.toUtf8 ().data (), mapset.toUtf8 ().data () );
1661
+ }
1662
+ G_CATCH ( QgsGrass::Exception &e )
1663
+ {
1664
+ warning ( e );
1665
+ vectDestroyMapStruct ( Map );
1666
+ return false ;
1667
+ }
1658
1668
1659
1669
if ( level < 2 )
1660
1670
{
1661
- QMessageBox::warning ( 0 , QObject::tr ( " Warning" ),
1662
- QObject::tr ( " Cannot read vector map region" ) );
1671
+ warning ( QObject::tr ( " Cannot read vector map region" ) );
1672
+ if ( level == 1 )
1673
+ {
1674
+ G_TRY
1675
+ {
1676
+ Vect_close ( Map );
1677
+ }
1678
+ G_CATCH ( QgsGrass::Exception &e )
1679
+ {
1680
+ QgsDebugMsg ( e.what () );
1681
+ }
1682
+ }
1683
+ vectDestroyMapStruct ( Map );
1663
1684
return false ;
1664
1685
}
1665
1686
1666
1687
BOUND_BOX box;
1667
- Vect_get_map_box ( & Map, &box );
1688
+ Vect_get_map_box ( Map, &box );
1668
1689
window->north = box.N ;
1669
1690
window->south = box.S ;
1670
1691
window->west = box.W ;
@@ -1686,7 +1707,8 @@ bool QgsGrass::mapRegion( QgsGrassObject::Type type, QString gisdbase,
1686
1707
}
1687
1708
G_adjust_Cell_head3 ( window, 0 , 0 , 0 );
1688
1709
1689
- Vect_close ( &Map );
1710
+ Vect_close ( Map );
1711
+ vectDestroyMapStruct ( Map );
1690
1712
}
1691
1713
else if ( type == QgsGrassObject::Region )
1692
1714
{
@@ -1700,8 +1722,16 @@ bool QgsGrass::mapRegion( QgsGrassObject::Type type, QString gisdbase,
1700
1722
return false ;
1701
1723
}
1702
1724
#else
1703
- // TODO7: unfortunately G__get_window does not return error code and calls G_fatal_error on error
1704
- G__get_window ( window, ( char * ) " windows" , map.toUtf8 ().data (), mapset.toUtf8 ().data () );
1725
+ // G__get_window does not return error code in GRASS 7 and calls G_fatal_error on error
1726
+ G_TRY
1727
+ {
1728
+ G__get_window ( window, ( char * ) " windows" , map.toUtf8 ().data (), mapset.toUtf8 ().data () );
1729
+ }
1730
+ G_CATCH ( QgsGrass::Exception &e )
1731
+ {
1732
+ warning ( e );
1733
+ return false ;
1734
+ }
1705
1735
#endif
1706
1736
}
1707
1737
return true ;
0 commit comments