[QGIS Commit] r8476 - in trunk/qgis/src: plugins/grass
providers/grass
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue May 20 18:09:40 EDT 2008
Author: jef
Date: 2008-05-20 18:09:40 -0400 (Tue, 20 May 2008)
New Revision: 8476
Modified:
trunk/qgis/src/plugins/grass/qgsgrassselect.cpp
trunk/qgis/src/providers/grass/qgsgrass.cpp
trunk/qgis/src/providers/grass/qgsgrass.h
trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
Log:
fix grass crash:
setlocale to "C" in getSRS() and catch fatal errors
(probably needed at much more places).
Modified: trunk/qgis/src/plugins/grass/qgsgrassselect.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassselect.cpp 2008-05-20 19:19:00 UTC (rev 8475)
+++ trunk/qgis/src/plugins/grass/qgsgrassselect.cpp 2008-05-20 22:09:40 UTC (rev 8476)
@@ -397,6 +397,7 @@
level = Vect_open_old_head (&map, (char *) mapName.ascii(),
(char *) mapset.ascii());
}
+ QgsGrass::clearErrorEnv();
if ( QgsGrass::getError() == QgsGrass::FATAL ) {
std::cerr << "Cannot open GRASS vector: " << QgsGrass::getErrorMessage().toLocal8Bit().data() << std::endl;
Modified: trunk/qgis/src/providers/grass/qgsgrass.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.cpp 2008-05-20 19:19:00 UTC (rev 8475)
+++ trunk/qgis/src/providers/grass/qgsgrass.cpp 2008-05-20 22:09:40 UTC (rev 8476)
@@ -16,6 +16,7 @@
/* $Id$ */
#include <iostream>
+#include <qgslogger.h>
#include "QString"
#include "q3process.h"
@@ -375,6 +376,7 @@
QString QgsGrass::mTmp;
jmp_buf QgsGrass::mFatalErrorEnv;
+bool QgsGrass::mFatalErrorEnvActive=false;
int QgsGrass::error_routine ( char *msg, int fatal)
{
@@ -383,15 +385,21 @@
int QgsGrass::error_routine ( const char *msg, int fatal)
{
- std::cerr << "error_routine (fatal = " << fatal << "): " << msg << std::endl;
+ QgsDebugMsg(QString("error_routine (fatal = %1): %2").arg(fatal).arg(msg));
error_message = msg;
if ( fatal )
- {
+ {
error = FATAL;
// we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process
- longjmp(mFatalErrorEnv, 1);
+ if( mFatalErrorEnvActive )
+ longjmp(mFatalErrorEnv, 1);
+ else
+ {
+ QMessageBox::warning( 0, QObject::tr("Uncatched fatal GRASS error"), msg );
+ abort();
+ }
}
else
error = WARNING;
@@ -416,9 +424,18 @@
jmp_buf GRASS_EXPORT &QgsGrass::fatalErrorEnv()
{
+ if(mFatalErrorEnvActive)
+ QgsDebugMsg("fatal error environment already active.");
+ mFatalErrorEnvActive = true;
return mFatalErrorEnv;
}
+void GRASS_EXPORT QgsGrass::clearErrorEnv()
+{
+ if(!mFatalErrorEnvActive)
+ QgsDebugMsg("fatal error environment already deactive.");
+ mFatalErrorEnvActive = false;
+}
QString GRASS_EXPORT QgsGrass::openMapset ( QString gisdbase, QString location, QString mapset )
{
Modified: trunk/qgis/src/providers/grass/qgsgrass.h
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.h 2008-05-20 19:19:00 UTC (rev 8475)
+++ trunk/qgis/src/providers/grass/qgsgrass.h 2008-05-20 22:09:40 UTC (rev 8476)
@@ -155,6 +155,7 @@
static GRASS_EXPORT QString versionString();
static GRASS_EXPORT jmp_buf& fatalErrorEnv();
+ static GRASS_EXPORT void clearErrorEnv();
private:
@@ -184,6 +185,7 @@
// Context saved before a call to routine that can produce a fatal error
static jmp_buf mFatalErrorEnv;
+ static bool mFatalErrorEnvActive;
};
#endif // QGSGRASS_H
Modified: trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrassprovider.cpp 2008-05-20 19:19:00 UTC (rev 8475)
+++ trunk/qgis/src/providers/grass/qgsgrassprovider.cpp 2008-05-20 22:09:40 UTC (rev 8476)
@@ -1250,8 +1250,24 @@
struct Cell_head cellhd;
+ QgsGrass::resetError();
QgsGrass::setLocation ( mGisdbase, mLocation );
- G_get_default_window(&cellhd);
+
+ char *oldlocale = setlocale(LC_ALL, NULL);
+ setlocale(LC_ALL, "C");
+
+ if ( setjmp(QgsGrass::fatalErrorEnv()) == 0 )
+ {
+ G_get_default_window(&cellhd);
+ }
+ QgsGrass::clearErrorEnv();
+
+ if ( QgsGrass::getError() == QgsGrass::FATAL ) {
+ setlocale(LC_ALL, oldlocale);
+ QgsDebugMsg(QString("Cannot get default window: %1").arg(QgsGrass::getErrorMessage()));
+ return QgsSpatialRefSys();
+ }
+
if (cellhd.proj != PROJECTION_XY) {
struct Key_Value *projinfo = G_get_projinfo();
struct Key_Value *projunits = G_get_projunits();
@@ -1260,6 +1276,8 @@
free ( wkt);
}
+ setlocale(LC_ALL, oldlocale);
+
QgsSpatialRefSys srs;
srs.createFromWkt(WKT);
More information about the QGIS-commit
mailing list