Apollo3zehn / PureHDF

A pure .NET library that makes reading and writing of HDF5 files (groups, datasets, attributes, ...) very easy.
MIT License
47 stars 16 forks source link

Stackoverflow exception when writing data set #86

Closed lellid closed 1 month ago

lellid commented 1 month ago

Hi, I have the following code:

var len = 3;
var dataArr = new double[len];
var dataset = new H5Dataset(dataArr, fileDims: [(ulong)len]);
var file = new H5File()
{
  ["raw"] = dataset,
};
file.Write(fileName);

(The reason why I used an H5Dataset instead of an array is that later on I want to add attributes to the dataset, and modify the dimensions) The code shows a StackoverflowException when it reaches file.Write, in the method H5NativeWriter.EncodeDataset. Is this a bug, or did I use something in the wrong way?

Best regards, Dirk

Apollo3zehn commented 1 month ago

Which version of PureHDF are you running and on which OS? With the current version (1.0.0-beta.16) the code

var len = 3;
var dataArr = new double[len];
var dataset = new H5Dataset(dataArr, fileDims: [(ulong)len]);
var file = new H5File()
{
    ["raw"] = dataset,
};

file.Write("/home/vincent/Downloads/out.h5");

runs well for me on Ubuntu 24.04.

Thanks :-)

lellid commented 1 month ago

It succeeds unter .Net8.05, but fails with a StackoverflowException under NetFramework 4.8.9232.0, using Windows 10.0.19045, with the version of PureHDF of 1.0.0-beta.16. An excerpt of the stack is:

System.Memory.dll!System.SpanHelpers.CopyTo<byte>(ref byte dst, int dstLength, ref byte src, int srcLength)
System.Memory.dll!System.Span<byte>.TryCopyTo(System.Span<byte> destination)    
System.Memory.dll!System.Span<byte>.ToArray()   
PureHDF.dll!PureHDF.StreamExtensions.Write(System.IO.Stream stream, System.Span<byte> buffer)   
PureHDF.dll!PureHDF.StreamExtensions.Write(System.IO.Stream stream, System.Span<byte> buffer)   
[The 1 frame(s) above this were repeated 12612 times]   
PureHDF.dll!PureHDF.StreamExtensions.Write(System.IO.Stream stream, System.Span<byte> buffer)   
PureHDF.dll!PureHDF.VFD.H5StreamDriver.Write(System.Span<byte> data)    
PureHDF.dll!PureHDF.VOL.Native.ObjectHeader2.Encode(PureHDF.VOL.Native.NativeWriteContext context)  
PureHDF.dll!PureHDF.H5NativeWriter.InternalEncodeDataset<double[], double>(PureHDF.H5Dataset dataset, double[] data, bool isScalar)

Hope that helps.

Best regards, Dirk

Apollo3zehn commented 1 month ago

Thanks for that hint, I will try to reproduce it!

Apollo3zehn commented 1 month ago

The bug should be solved in version v1.0.0-beta.17 :-)

lellid commented 1 month ago

Yes, it works now! Thanks a lot!