Opened 19 years ago
Closed 17 years ago
#641 closed defect (fixed)
crash when creating an empty shapefile and insert a new feature into it
Reported by: | Owned by: | Mateusz Łoskot | |
---|---|---|---|
Priority: | normal | Milestone: | 1.4.2 |
Component: | OGR_SF | Version: | unspecified |
Severity: | normal | Keywords: | |
Cc: | warmerdam |
Description (last modified by )
Hi, I'm not sure if this is a bug in OGR or in my program. What i try to do is to create an empty shapefile and later to open this shapefile and insert features into it.
When i try to add the feature, a crash happens. Also i noticed that a field, which i created on the empty shapefile is not recognised when the empty layer is opened.
Below is my source code and the debugger backtrace after the crash.
A .tgz of the created files (.shp,.dbf,etc.) befor adding a feature is on ftp://ftp.geo.unizh.ch/pub/mhugent/newlayertest.tgz
//create an empty layer and add a field to it OGRwkbGeometryType geomtype=(OGRwkbGeometryType)((int)vectortype); QString mOutputFormat = "ESRI Shapefile"; QString mOutputFileName = uri; #ifdef WIN32 QString outname=mOutputFileName.mid(mOutputFileName.findRev("\\")+1,mOutputFileName.length()); #else QString outname=mOutputFileName.mid(mOutputFileName.findRev("/")+1,mOutputFileName.length()); #endif OGRSFDriverRegistrar* driverregist = OGRSFDriverRegistrar::GetRegistrar(); if(driverregist==0) { return false; } OGRSFDriver* driver = driverregist->GetDriverByName(mOutputFormat); if(driver==0) { return false; } OGRDataSource* datasource = driver->CreateDataSource(mOutputFileName,NULL); if(datasource==0) { return false; } OGRSpatialReference reference; OGRLayer* layer = datasource->CreateLayer(outname.latin1 (),&reference,geomtype,NULL); if(layer==0) { return false; } OGRFieldDefn fielddef("dummy",OFTReal); fielddef.SetWidth(1); fielddef.SetPrecision(1); if(layer->CreateField(&fielddef,FALSE)!=OGRERR_NONE) { return false; }
The debugger output when inserting a new feature afterwards:
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 1091298272 (LWP 25403)] 0x40a70218 in DBFGetRecordCount () from /usr/local/lib/libgdal.so.1 (gdb) backtrace #0 0x40a70218 in DBFGetRecordCount () from /usr/local/lib/libgdal.so.1 #1 0x40b0992f in SHPWriteOGRFeature () from /usr/local/lib/libgdal.so.1 #2 0x40af4936 in OGRShapeLayer::CreateFeature () from /usr/local/lib/libgdal.so.1 #3 0x41923027 in QgsShapeFileProvider::commitFeature (this=0x85a0668, f=0x85f7cb0) at qgsshapefileprovider.cpp:820 #4 0x41922e14 in QgsShapeFileProvider::commitChanges (this=Variable "this" is not available. ) at stl_list.h:167
Marco
Attachments (3)
Change History (10)
comment:1 by , 17 years ago
Cc: | added |
---|---|
Description: | modified (diff) |
Milestone: | → 1.4.2 |
Owner: | changed from | to
Priority: | high → normal |
comment:2 by , 17 years ago
Description: | modified (diff) |
---|
comment:3 by , 17 years ago
Status: | new → assigned |
---|
Unfortunately, due to the fact this issue as reported long time ago, the file exposed to under following URL is no longer available:
ftp://ftp.geo.unizh.ch/pub/mhugent/newlayertest.tgz
I'll try to reproduce the problem using my own empty shapefile and the issue description.
comment:4 by , 17 years ago
Here I test the first part of the problem. I'm trying to reproduce very similar program as pasted in the report above and run.
NOTE: The program above looks as incomplete - there is no CreateFeature() call. Also, my first test - test.cpp - does also not call CreateFeature but just generates empty shapefile.
- Compile test program
mloskot:~/dev/gdal/bugs/641$ make g++ -g -I/home/mloskot/dev/gdal/_svn/trunk/gdal \ -I/home/mloskot/dev/gdal/_svn/trunk/gdal/port \ -I/home/mloskot/dev/gdal/_svn/trunk/gdal/gcore \ -I/home/mloskot/dev/gdal/_svn/trunk/gdal/ogr \ -I/home/mloskot/dev/gdal/_svn/trunk/gdal/ogr/ogrsf_frmts test.cpp -o test \ -L/home/mloskot/dev/gdal/_svn/trunk/gdal -lgdal
- Run the program to create empty.shp data
mloskot:~/dev/gdal/bugs/641$ ls Makefile test test.cpp mloskot:~/dev/gdal/bugs/641$ ./test mloskot:~/dev/gdal/bugs/641$ ls empty.dbf empty.prj empty.shp empty.shx Makefile test test.cpp
- Investigate the results with Shapelib utilities
mloskot:~/dev/gdal/bugs/641$ shpdump empty.shp Shapefile Type: Point # of Shapes: 0 File Bounds: ( 0.000, 0.000,0,0) to ( 0.000, 0.000,0,0) mloskot:~/dev/gdal/bugs/641$ dbfdump -h empty.shp Field 0: Type=Double, Title=`dummy', Width=1, Decimals=1 dummy
- Investigate the results using ogrinfo
mloskot:~/dev/gdal/bugs/641$ ogrinfo -ro empty.shp empty OGR: OGROpen(empty.shp/0x804e550) succeeded as ESRI Shapefile. INFO: Open of `empty.shp' using driver `ESRI Shapefile' successful. OGR: GetLayerCount() = 1 Layer name: empty Geometry: Point Feature Count: 0 Extent: (0.000000, 0.000000) - (0.000000, 0.000000) Layer SRS WKT: (unknown) dummy: Real (1.1)
This part of the problem works.
comment:5 by , 17 years ago
Here I test adding sample feature to empty shapefile created using test.cpp program. The program adding a feature is called test2.cpp
- Compile all again
mloskot:~/dev/gdal/bugs/641$ make
- Create empty.shp
mloskot:~/dev/gdal/bugs/641$ ./test mloskot:~/dev/gdal/bugs/641$ ls empty.dbf empty.prj empty.shp empty.shx Makefile test test2 test2.cpp test.cpp
- Check empty.shp
mloskot:~/dev/gdal/bugs/641$ ogrinfo -ro empty.shp empty OGR: OGROpen(empty.shp/0x804e550) succeeded as ESRI Shapefile. INFO: Open of `empty.shp' using driver `ESRI Shapefile' successful. OGR: GetLayerCount() = 1 Layer name: empty Geometry: Point Feature Count: 0 Extent: (0.000000, 0.000000) - (0.000000, 0.000000) Layer SRS WKT: (unknown) dummy: Real (1.1)
- Open empty.shp again and add sample feature
mloskot:~/dev/gdal/bugs/641$ ./test2 OGR: OGROpen(empty.shp/0x804d760) succeeded as ESRI Shapefile. mloskot:~/dev/gdal/bugs/641$ ogrinfo -ro empty.shp empty OGR: OGROpen(empty.shp/0x804e550) succeeded as ESRI Shapefile. INFO: Open of `empty.shp' using driver `ESRI Shapefile' successful. OGR: GetLayerCount() = 1 Layer name: empty Geometry: Point Feature Count: 1 Extent: (1.250000, 2.350000) - (1.250000, 2.350000) Layer SRS WKT: (unknown) dummy: Real (1.1) OGRFeature(empty):0 dummy (Real) = 3.0 POINT (1.25 2.35) Shape: 1 features read on layer
I think everything works here very well.
comment:6 by , 17 years ago
As I checked above, everything works well: a) create empty shapefile and close it b) reopen and add features.
Marco, please, if you could confirm my analysis is OK and everything works for you too, I'd be thankful.
I'm closing this ticket as fixed.
comment:7 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Mateusz,
I'd like you to try to reproduce this problem and see if it still exists. If so, lets fix it. If the fix is straight forward it can go into 1.4.2. If it seems tricky, perhaps just trunk.