Skip to content

Commit ad1fef9

Browse files
committedMay 29, 2018
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" test. Refs #14752
1 parent 5ab3fe4 commit ad1fef9

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed
 

‎src/core/geometry/qgsgeos.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,29 @@ static void throwGEOSException( const char *fmt, ... )
5858
va_end( ap );
5959

6060
qWarning( "GEOS exception: %s", buffer );
61-
62-
throw GEOSException( QString::fromUtf8( buffer ) );
61+
QString message = QString::fromUtf8( buffer );
62+
63+
#ifdef _MSC_VER
64+
// stupid stupid MSVC, *SOMETIMES* raises it's own exception if we throw GEOSException, resulting in a crash!
65+
// see https://issues.qgis.org/issues/14752
66+
// if you want to test alternative fixes for this, run the testqgsexpression.cpp test suite - that will crash
67+
// and burn on the "line_interpolate_point point" test if a GEOSException is thrown.
68+
// TODO - find a real fix for the underlying issue
69+
try
70+
{
71+
throw GEOSException( message );
72+
}
73+
catch ( ... )
74+
{
75+
// oops, msvc threw an exception when we tried to throw the exception!
76+
// just throw nothing instead (except your mouse at your monitor)
77+
}
78+
#else
79+
throw GEOSException( message );
80+
#endif
6381
}
6482

83+
6584
static void printGEOSNotice( const char *fmt, ... )
6685
{
6786
#if defined(QGISDEBUG)

0 commit comments

Comments
 (0)
Please sign in to comment.