Skip to content

ToComplete() overflows stack #122

@f2heartz

Description

@f2heartz
using OsmSharp.Streams;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace Sample.CompleteStream
{
    class Program
    {
        /// <summary>
        /// Downloads a file if it doesn't exist yet.
        /// </summary>
        public static async Task ToFile(string url, string filename)
        {
            if (!File.Exists(filename))
            {
                var client = new HttpClient();
                using (var stream = await client.GetStreamAsync(url))
                using (var outputStream = File.OpenWrite(filename))
                {
                    stream.CopyTo(outputStream);
                }
            }
        }

        static void Main(string[] args)
        {
            ToFile("http://download.openstreetmap.fr/extracts/europe/ukraine//kiev.osm.pbf", "kiev.osm.pbf").Wait();

            using (var fileStream = File.OpenRead("kiev.osm.pbf"))
            {
                // create source stream.
                var source = new PBFOsmStreamSource(fileStream);

                var complete = source.Where(_ => true).ToComplete();

                var counted = complete.GroupBy(osmGeo => osmGeo.Type).Select(group => (group.Key, group.Count()));
                foreach (var (k, v) in counted)
                {
                    Console.WriteLine($"{k}={v}");
                }
            }
        }
    }
}
  1. Run the code above against either current master or with dotnet add package OsmSharp for either netcoreapp2.1 or netcoreapp3.1.
  2. See Stack Overflow printed on the console with no additional info.

P.S. Omitting .Where(_ => true) will fail in the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions