OsmSharp / ui

The UI components.
http://osmsharp.com/
GNU General Public License v2.0
139 stars 91 forks source link

NullReferenceException in PBFOsmStreamSource.MoveNextWay() at last record read. #257

Closed Alexey-Stolyarov closed 9 years ago

Alexey-Stolyarov commented 9 years ago

It fails when using MoveNextWay(), but work ok with MoveNext().

at OsmSharp.Osm.PBF.Dense.Decompressor.ProcessPrimitiveBlock(PrimitiveBlock block, Boolean ignoreNodes, Boolean ignoreWays, Boolean ignoreRelations) at OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource.MoveToNextPrimitive(Boolean ignoreNodes, Boolean ignoreWays, Boolean ignoreRelations) at OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource.MoveNext(Boolean ignoreNodes, Boolean ignoreWays, Boolean ignoreRelations) at OsmSharp.Osm.Streams.OsmStreamSource.MoveNextWay() at ...

Tested on http://download.geofabrik.de/europe/germany/bayern/oberbayern-latest.osm.pbf

xivk commented 9 years ago

At moment default behaviour is that you should call Initialize() before reading from the source. But I will leave this issue open because what could change is:

The source is also an IEnumerable. If you use that you can also enumerate all objects.

Alexey-Stolyarov commented 9 years ago

@xivk, code below is failing when I execute it. I used Initialize() method. In XmlOsmStreamSource there is no such issue.

        [Test]
        public void Test()
        {
            using (var fileStream = File.OpenRead(@"d:\osm\oberbayern-latest.osm.pbf"))
            {
                using (var reader = new PBFOsmStreamSource(fileStream))
                {
                    reader.Initialize();
                    var counter = 0;        
                    while (reader.MoveNextWay())
                    {
                        if (counter++%10000==0)
                        {
                            Debug.Print(counter.ToString());
                        }
                    }
                }
            }
        }
TomQv commented 9 years ago

Might be this issue with incomplete ways intersecting the bounding box of the pbf and missing nodes,remember? Tom

xivk commented 9 years ago

@APLANA-Alexey-Stolyarov Thanks for reporting this, OsmSharp just got a little bit better thanks to you! :+1:

@TomQv This issue is a bit different as here we are not trying to assemble ways with al their nodes just processing the raw data.