Skip to content

Commit 793b432

Browse files
author
jef
committed
fix GEOS initialization
git-svn-id: http://svn.osgeo.org/qgis/trunk@9329 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1caa7d0 commit 793b432

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/core/qgsgeometry.cpp

+24-21
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ email : morb at ozemail dot com dot au
3838
class GEOSException
3939
{
4040
public:
41-
GEOSException( char *theMsg )
41+
GEOSException( const char *theMsg )
4242
{
4343
if ( strcmp( theMsg, "Unknown exception thrown" ) == 0 && lastMsg )
4444
{
4545
delete [] theMsg;
46-
msg = new char[strlen( lastMsg )+1];
47-
strcpy( msg, lastMsg );
46+
char *aMsg = new char[strlen( lastMsg )+1];
47+
strcpy( aMsg, lastMsg );
48+
msg = aMsg;
4849
}
4950
else
5051
{
@@ -72,13 +73,13 @@ class GEOSException
7273
}
7374

7475
private:
75-
char *msg;
76+
const char *msg;
7677
static const char *lastMsg;
7778
};
7879

7980
const char *GEOSException::lastMsg = NULL;
8081

81-
void throwGEOSException( const char *fmt, ... )
82+
static void throwGEOSException( const char *fmt, ... )
8283
{
8384
va_list ap;
8485
va_start( ap, fmt );
@@ -92,7 +93,7 @@ void throwGEOSException( const char *fmt, ... )
9293
throw GEOSException( msg );
9394
}
9495

95-
void printGEOSNotice( const char *fmt, ... )
96+
static void printGEOSNotice( const char *fmt, ... )
9697
{
9798
#if defined(QGISDEBUG)
9899
va_list ap;
@@ -106,6 +107,23 @@ void printGEOSNotice( const char *fmt, ... )
106107
#endif
107108
}
108109

110+
class GEOSInit
111+
{
112+
public:
113+
GEOSInit()
114+
{
115+
initGEOS( printGEOSNotice, throwGEOSException );
116+
}
117+
118+
~GEOSInit()
119+
{
120+
finishGEOS();
121+
}
122+
};
123+
124+
static GEOSInit geosinit;
125+
126+
109127
#if defined(GEOS_VERSION_MAJOR) && (GEOS_VERSION_MAJOR<3)
110128
#define GEOSGeom_getCoordSeq(g) GEOSGeom_getCoordSeq( (GEOSGeometry *) g )
111129
#define GEOSGetExteriorRing(g) GEOSGetExteriorRing( (GEOSGeometry *)g )
@@ -154,33 +172,21 @@ static GEOSGeometry *cloneGeosGeom( const GEOSGeometry *geom )
154172
#define GEOSGeom_clone(g) cloneGeosGeom(g)
155173
#endif
156174

157-
int QgsGeometry::refcount = 0;
158-
159175
QgsGeometry::QgsGeometry()
160176
: mGeometry( 0 ),
161177
mGeometrySize( 0 ),
162178
mGeos( 0 ),
163179
mDirtyWkb( FALSE ),
164180
mDirtyGeos( FALSE )
165181
{
166-
if ( refcount++ == 0 )
167-
{
168-
initGEOS( printGEOSNotice, throwGEOSException );
169-
}
170182
}
171183

172-
173184
QgsGeometry::QgsGeometry( QgsGeometry const & rhs )
174185
: mGeometry( 0 ),
175186
mGeometrySize( rhs.mGeometrySize ),
176187
mDirtyWkb( rhs.mDirtyWkb ),
177188
mDirtyGeos( rhs.mDirtyGeos )
178189
{
179-
if ( refcount++ == 0 )
180-
{
181-
initGEOS( printGEOSNotice, throwGEOSException );
182-
}
183-
184190
if ( mGeometrySize && rhs.mGeometry )
185191
{
186192
mGeometry = new unsigned char[mGeometrySize];
@@ -210,9 +216,6 @@ QgsGeometry::~QgsGeometry()
210216
{
211217
GEOSGeom_destroy( mGeos );
212218
}
213-
214-
if ( --refcount == 0 )
215-
finishGEOS();
216219
}
217220

218221
static unsigned int getNumGeosPoints( const GEOSGeometry *geom )

0 commit comments

Comments
 (0)