UndefRefError: access to undefined reference, how to fix the following error?

I’m running some Julia code and the error message I get is as the following:

UndefRefError: access to undefined reference
   in top-level scope at base/None
   in simulate! at do_sim.jl:10
   #simulate!#46 at so_sim.jl:38
   simulateNextEvent! at do_sim.jl:84
   simulateEvent! at do_sim.jl:184
   findAmbToCallReturnRouteDistTime! at decisions.jl:117
   get property at base/sysing.jl:18

Yet, I have checked the code several times and it should be good. Any comments about where and how to fix the error here?

Here’s one way that such an error can get thrown:

julia> r = Ref{Any}()
Base.RefValue{Any}(#undef)

julia> r[]
ERROR: UndefRefError: access to undefined reference

Somewhere in your code you’re trying to access a reference that was initialized as undef and never set. Impossible to say more without the code itself.

1 Like

What is Ref by the way?

It’s just a box that can hold something — and what it is holding onto can change.

https://docs.julialang.org/en/v1/base/c/#Core.Ref

2 Likes