Skip to content
Browse files

Workaround crash in msvc when raising a GEOS exception

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"

Refs #14752
  • Loading branch information
nyalldawson committed May 29, 2018
1 parent 5ab3fe4 commit ad1fef9f7c559263d25ae062a58562d71bb3778b
Showing with 21 additions and 2 deletions.
  1. +21 −2 src/core/geometry/qgsgeos.cpp
@@ -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
// 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
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)
throw GEOSException( message );

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

0 comments on commit ad1fef9

Please sign in to comment.
You can’t perform that action at this time.