Skip to content

Commit

Permalink
Workaround crash in msvc when raising a GEOS exception
Browse files Browse the repository at this point in the history
In some circumstances MSVC tries to raise it's own internal
exception when we try to raise a GEOSException. This results
in a hard crash of QGIS.

To workaround this, we cautiously try to raise a GEOSException
on msvc builds, catching all other raised exceptions if
throwing the GEOSException triggers them. This at least allows
us to gracefully handle the geos error without crashing QGIS
(although the detailed GEOS error message is not available
when this situation occurs... but that's still better than
a crash!).

If you want to try to find a better fix for this, the
testqgsexpression.cpp test suite will demonstrate the issue.

Without this fix the test will crash on the "line_interpolate_point point"
test.

Refs #14752
  • Loading branch information
nyalldawson committed May 29, 2018
1 parent 5ab3fe4 commit ad1fef9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/core/geometry/qgsgeos.cpp
Expand Up @@ -58,10 +58,29 @@ static void throwGEOSException( const char *fmt, ... )
va_end( ap );

qWarning( "GEOS exception: %s", buffer );

throw GEOSException( QString::fromUtf8( buffer ) );
QString message = QString::fromUtf8( buffer );

#ifdef _MSC_VER
// stupid stupid MSVC, *SOMETIMES* raises it's own exception if we throw GEOSException, resulting in a crash!
// see https://issues.qgis.org/issues/14752
// if you want to test alternative fixes for this, run the testqgsexpression.cpp test suite - that will crash
// and burn on the "line_interpolate_point point" test if a GEOSException is thrown.
// TODO - find a real fix for the underlying issue
try
{
throw GEOSException( message );
}
catch ( ... )
{
// oops, msvc threw an exception when we tried to throw the exception!
// just throw nothing instead (except your mouse at your monitor)
}
#else
throw GEOSException( message );
#endif
}


static void printGEOSNotice( const char *fmt, ... )
{
#if defined(QGISDEBUG)
Expand Down

0 comments on commit ad1fef9

Please sign in to comment.