shintadono / laszip.net

LAS/LAZ library for C#
GNU Lesser General Public License v2.1
38 stars 26 forks source link

NullReference exception by reading LAZ file #3

Closed ilCosmico closed 9 years ago

ilCosmico commented 9 years ago

Hello,

I tried to load different LAZ files but I always get a NullReference exception.

Here below my code snippet for the reading:

List points = new List(); laszip.net.laszip_dll dll = new laszip.net.laszip_dll(); bool is_compressed = true; dll.laszip_open_reader(fileName, ref is_compressed);
long expectedPointCount = (long)dll.header.number_of_point_records; double[] coordinates = new double[3]; int pointIndex = 0; while (dll.laszip_read_point() == 0) { pointIndex++;
dll.laszip_get_coordinates(coordinates); points.Add((float)coordinates[0]); points.Add((float)coordinates[1]); points.Add((float)coordinates[2]); } long pointCount; dll.laszip_get_point_count(out pointCount);

Here a link to download sample LAZ files: http://www.liblas.org/samples/

shintadono commented 9 years ago

Thanks for the report. Hope that the fix complete and that I didn't overlooked something.

ilCosmico commented 9 years ago

It seems quite good, but now it gives the following error:

image

The final error message is: "Reading point with index 2155617 of 2155617 total points" So I suppose it simply has reached the end of file... perhaps you could add a check like this:

image

What do you think?

shintadono commented 9 years ago

This library is only a C# port of https://github.com/LASzip/LASzip and I'm trying to keep it as close as possible to the original. The idea of the originals API (which I'm only using) is: You have to check the results of laszip_get_point_count(out long count) and laszip_get_number_of_point(out long npoints) to determine, if you can read another point.

I have to admit, I would use a completely different API, which would be more on the StreamReader or BinaryReader API, if I were the maintainer (Martin Isenburg). But that is a completely different matter and would be a completely different library.

ilCosmico commented 9 years ago

Ok, clear... thank you for the explanation and for the quick fix of course!

Great Job!