JuliaIO / JLD.jl

Saving and loading julia variables while preserving native types
MIT License
278 stars 55 forks source link

JLD error when using jldopen on a nested mutable struct before and after loading DSP.jl #313

Open rgaudette opened 2 years ago

rgaudette commented 2 years ago

I think I have found a strange interaction between JLD.jl and DSP.jl. If I call jldopen to save a nested mutable struct, then load DSP.jl, and then call jldopen to save a nested mutable struct again, I get the following error:

ERROR: LoadError: HDF5.API.H5Error("Error getting the number of members", 1008806316530991122).

This is using Julia 1.7.2, freshly updated.

Here is small section of code that I think captures the problem

using JLD

# If using DSP is executed here then this script does not crash
# using DSP

# If the following 2 structs are not mutable, this script does not crash
"""
A basic mutable X & Y Pair
"""
mutable struct MXYPair{T <: Real}
    x::T
    y::T
end # MXYPair

"""
A mutable 2D rectangle
"""
mutable struct MRectangle{T <: Real}
    origin::MXYPair{T}
    width::T
    height::T
end # Rectangle

mrect = MRectangle(MXYPair(1.0, 2.0), 3.0, 4.0)

# If using DSP is executed here then this script does not crash
# using DSP
jldopen("file1.jld", "w") do file
    write(file, "mrect", mrect)
end

# If the DSP module is loaded (using or import) JLD crashes on the following write
using DSP

jldopen("file2.jld", "w") do file
    write(file, "mrect", mrect)
end