Opened 14 years ago

Closed 14 years ago

#3765 closed defect (fixed)

Mapinfo assertion failure doing QGIS GetFeature(fid)

Reported by: warmerdam Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords: mitab mapinfo
Cc: Daniel Morissette, aboudreault

Description

If I add the usa/statecaps.mif file as a vector layer in qgis and then use the identify tool to query one of the points I get an assertion failure in the mitab driver.

ERROR 7: Assertion `m_nPreloadedId == nFeatureId' failed
in file `mitab_miffile.cpp', line 1217

The gdb traceback looks like:

(gdb) where 16
#0  0x00007ffff2f2c4b5 in *__GI_raise (sig=<value optimized out>)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff2f2ff50 in *__GI_abort () at abort.c:92
#2  0x00007ffff459224b in CPLErrorV (eErrClass=CE_Fatal, err_no=7, 
    fmt=0x7ffff4a39eb0 "Assertion `%s' failed\nin file `%s', line %d\n", 
    args=0x7fffffffa350) at cpl_error.cpp:237
#3  0x00007ffff4591f20 in CPLError (eErrClass=CE_Fatal, err_no=7, 
    fmt=0x7ffff4a39eb0 "Assertion `%s' failed\nin file `%s', line %d\n")
    at cpl_error.cpp:135
#4  0x00007ffff4592d9d in _CPLAssert (
    pszExpression=0x7ffff4a4dcae "m_nPreloadedId == nFeatureId", 
    pszFile=0x7ffff4a4d9cc "mitab_miffile.cpp", iLine=1217)
    at cpl_error.cpp:759
#5  0x00007ffff469f5ad in MIFFile::GotoFeature (this=0x1ef7230, nFeatureId=15)
    at mitab_miffile.cpp:1217
#6  0x00007ffff469f6cd in MIFFile::GetFeatureRef (this=0x1ef7230, 
    nFeatureId=15) at mitab_miffile.cpp:1278
#7  0x00007ffff4686843 in IMapInfoFile::GetFeature (this=0x1ef7230, 
    nFeatureId=15) at mitab_imapinfofile.cpp:409
#8  0x00007ffff4741058 in OGR_L_GetFeature (hLayer=0x1ef7230, nFeatureId=15)
    at ogrlayer.cpp:350
#9  0x00007fffddb24dbf in QgsOgrProvider::featureAtId (this=0x2123420, 
    featureId=15, feature=..., fetchGeometry=true, fetchAttributes=...)
---Type <return> to continue, or q <return> to quit---
    at /home/warmerda/pkg/qgis-svn/src/providers/ogr/qgsogrprovider.cpp:408
#10 0x00007ffff7673aea in QgsVectorLayer::featureAtId (this=0x25a3d00, 
    featureId=15, f=..., fetchGeometries=true, fetchAttributes=false)
    at /home/warmerda/pkg/qgis-svn/src/core/qgsvectorlayer.cpp:1721
#11 0x00000000005d0371 in QgsIdentifyResults::highlightFeature (
    this=0x2109d80, item=0x1cf9b10)
    at /home/warmerda/pkg/qgis-svn/src/app/qgsidentifyresults.cpp:741
#12 0x00000000005d11dc in QgsIdentifyResults::highlightLayer (this=0x2109d80, 
    item=0x20f1690)
    at /home/warmerda/pkg/qgis-svn/src/app/qgsidentifyresults.cpp:909
#13 0x00000000005cf955 in QgsIdentifyResults::handleCurrentItemChanged (
    this=0x2109d80, current=0x20f1690, previous=0x0)
    at /home/warmerda/pkg/qgis-svn/src/app/qgsidentifyresults.cpp:607
#14 0x00000000007c7153 in QgsIdentifyResults::qt_metacall (this=0x2109d80, 
    _c=QMetaObject::InvokeMetaMethod, _id=19, _a=0x7fffffffa950)
    at /home/warmerda/pkg/qgis-svn/build/src/app/moc_qgsidentifyresults.cxx:127
#15 0x00007ffff6609ddc in QMetaObject::activate (sender=0x1fc2cd0, 
    from_signal_index=<value optimized out>, 
    to_signal_index=<value optimized out>, argv=0xffffffffffffffff)
    at kernel/qobject.cpp:3113

Attempts to reproduce the problem with a GetFeature() call in ogrinfo did not succeed. The following works fine:

ogrinfo -fid 15 statecap.mif statecap -fid 15 --debug off
Had to open data source read-only.
INFO: Open of `statecap.mif'
      using driver `MapInfo File' successful.

Layer name: statecap
Geometry: Unknown (any)
Feature Count: 51
Extent: (-157.804233, 21.317250) - (-69.700000, 58.416667)
Layer SRS WKT:
GEOGCS["unnamed",
    DATUM["MIF 0",
        SPHEROID["WGS 84 (MAPINFO Datum 0)",6378137.01,298.257223563],
        TOWGS84[0,0,0,-0,-0,-0,0]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433]]
Capital: String (40.0)
State: String (2.0)
FIPS_Code: String (2.0)
Pop_1990: Real (11.0)
Num_HU_90: Real (11.0)
OGRFeature(statecap):15
  Capital (String) = Springfield
  State (String) = IL
  FIPS_Code (String) = 17
  Pop_1990 (Real) =      105227
  Num_HU_90 (Real) =       48534
  Style = SYMBOL(a:0,c:#ff0000,s:12pt,id:"mapinfo-sym-35,ogr-sym-10")
  POINT (-89.644654 39.781433)

I presume there is some particular sequence of calls in QGIS that is triggering the problem. The problem isn't pressing for me now, but I thought I should file a ticket so it could be investigated when time permits.

Attachments (1)

fix3765.diff (489 bytes ) - added by jef 14 years ago.
bug appears when a feature is sequently retrieved twice. fix attached.

Download all attachments as: .zip

Change History (4)

comment:1 by warmerdam, 14 years ago

<jef> FrankW: no crash here, but highlighting jumps for me on statecap.mif. eg. OGR_L_GetFeature fid=3 retrieves a feature on which OGR_F_GetFID returns 4.

by jef, 14 years ago

Attachment: fix3765.diff added

bug appears when a feature is sequently retrieved twice. fix attached.

comment:2 by Even Rouault, 14 years ago

Cc: aboudreault added

I've also hit the same crash with QGIS (GDAL must be compiled in debug mode so that assertions are ON) and reduced it to the same scenario.

With Alan's latest sync with MITAB CVS, the error is now reported at:

ERROR 7: Assertion `m_nPreloadedId == nFeatureId' failed
in file `mitab_miffile.cpp', line 1244

Example how to reproduce :

ogr2ogr -f "Mapinfo file" poly.mif ../autotest/ogr/data/poly.shp

then

python
>>> import ogr
>>> ds = ogr.Open('poly.mif')
>>> lyr = ds.GetLayer(0)
>>> feat = lyr.GetFeature(1)
>>> feat = lyr.GetFeature(1)
ERROR 7: Assertion `m_nPreloadedId == nFeatureId' failed
in file `mitab_miffile.cpp', line 1244


comment:3 by aboudreault, 14 years ago

Resolution: fixed
Status: newclosed

I've looked if we couldn't avoid to read twice the mif feature in the file for that case but we would have to return a cloned feature everytime we call GetFeature(). Since getting twice the same feature id is no very frequent.. it is more efficient to let the code as it is.

Note that when trying to convert that poly.shp file to poly.tab rather than .mif, I got many Warning 503: Integer bounds overflow errors. Fixed in mitab CVS HEAD (will be in 2.0) and in gdal in r20832.

Note: See TracTickets for help on using tickets.