mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
fix grass crash:
setlocale to "C" in getSRS() and catch fatal errors (probably needed at much more places). git-svn-id: http://svn.osgeo.org/qgis/trunk@8476 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
6906b9ebb8
commit
61e3fe93a3
@ -397,6 +397,7 @@ QStringList QgsGrassSelect::vectorLayers ( QString gisdbase,
|
||||
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;
|
||||
|
@ -16,6 +16,7 @@
|
||||
/* $Id$ */
|
||||
|
||||
#include <iostream>
|
||||
#include <qgslogger.h>
|
||||
|
||||
#include "QString"
|
||||
#include "q3process.h"
|
||||
@ -375,6 +376,7 @@ QString QgsGrass::mGisrc;
|
||||
QString QgsGrass::mTmp;
|
||||
|
||||
jmp_buf QgsGrass::mFatalErrorEnv;
|
||||
bool QgsGrass::mFatalErrorEnvActive=false;
|
||||
|
||||
int QgsGrass::error_routine ( char *msg, int fatal)
|
||||
{
|
||||
@ -383,7 +385,7 @@ int QgsGrass::error_routine ( char *msg, int fatal)
|
||||
|
||||
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;
|
||||
|
||||
@ -391,7 +393,13 @@ int QgsGrass::error_routine ( const char *msg, int fatal)
|
||||
{
|
||||
error = FATAL;
|
||||
// we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process
|
||||
if( mFatalErrorEnvActive )
|
||||
longjmp(mFatalErrorEnv, 1);
|
||||
else
|
||||
{
|
||||
QMessageBox::warning( 0, QObject::tr("Uncatched fatal GRASS error"), msg );
|
||||
abort();
|
||||
}
|
||||
}
|
||||
else
|
||||
error = WARNING;
|
||||
@ -416,9 +424,18 @@ QString GRASS_EXPORT QgsGrass::getErrorMessage ( void )
|
||||
|
||||
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 )
|
||||
{
|
||||
|
@ -155,6 +155,7 @@ public:
|
||||
static GRASS_EXPORT QString versionString();
|
||||
|
||||
static GRASS_EXPORT jmp_buf& fatalErrorEnv();
|
||||
static GRASS_EXPORT void clearErrorEnv();
|
||||
|
||||
|
||||
private:
|
||||
@ -184,6 +185,7 @@ private:
|
||||
|
||||
// Context saved before a call to routine that can produce a fatal error
|
||||
static jmp_buf mFatalErrorEnv;
|
||||
static bool mFatalErrorEnvActive;
|
||||
};
|
||||
|
||||
#endif // QGSGRASS_H
|
||||
|
@ -1250,8 +1250,24 @@ QgsSpatialRefSys QgsGrassProvider::getSRS()
|
||||
|
||||
struct Cell_head cellhd;
|
||||
|
||||
QgsGrass::resetError();
|
||||
QgsGrass::setLocation ( mGisdbase, mLocation );
|
||||
|
||||
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 @@ QgsSpatialRefSys QgsGrassProvider::getSRS()
|
||||
free ( wkt);
|
||||
}
|
||||
|
||||
setlocale(LC_ALL, oldlocale);
|
||||
|
||||
QgsSpatialRefSys srs;
|
||||
srs.createFromWkt(WKT);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user