# Trying to debug ReadOnlyMemoryError()

**URL:** https://discourse.julialang.org/t/trying-to-debug-readonlymemoryerror/124763
**Category:** General Usage
**Tags:** question
**Created:** [January 14, 2025, 1:34pm UTC](https://discourse.julialang.org/t/trying-to-debug-readonlymemoryerror/124763 "2025-01-14T13:34:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [January 14, 2025, 1:34pm UTC](https://discourse.julialang.org/t/trying-to-debug-readonlymemoryerror/124763/1 "2025-01-14T13:34:38Z")

</div>

When precompiling the main branch of KiteModels.jl I get:

```julia
julia> integrator = KiteModels.init_sim!(kps4_; delta=0.03, stiffness_factor=0.05, prn=false) 
ERROR: ReadOnlyMemoryError()
Stacktrace:
  [1] _evaluate(t::Vector{Float64}, c::Vector{Float64}, k::Int64, x::Float64, bc::Int64)
    @ Dierckx ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:279
  [2] evaluate
    @ ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:296 [inlined]
  [3] Spline1D
    @ ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:1112 [inlined]
  [4] calc_aero_forces!
    @ ~/repos/KiteModels.jl/src/KPS4.jl:359 [inlined]
  [5] residual!(res::StaticArraysCore.MVector{…}, yd::StaticArraysCore.MVector{…}, y::StaticArraysCore.MVector{…}, s::KPS4{…}, time::Float64)
    @ KiteModels ~/repos/KiteModels.jl/src/KPS4.jl:499
  [6] (::KiteModels.var"#test_initial_condition!#20"{Float64, KPS4{…}, StaticArraysCore.MVector{…}})(F::Vector{Float64}, x::Vector{Float64})
    @ KiteModels ~/repos/KiteModels.jl/src/KPS4.jl:654
  [7] (::NLSolversBase.var"#fj_finitediff!#21"{…})(F::Vector{…}, J::Matrix{…}, x::Vector{…})
    @ NLSolversBase ~/.julia/packages/NLSolversBase/kavn7/src/objective_types/oncedifferentiable.jl:138
  [8] value_jacobian!!(obj::NLSolversBase.OnceDifferentiable{Vector{…}, Matrix{…}, Vector{…}}, F::Vector{Float64}, J::Matrix{Float64}, x::Vector{Float64})
    @ NLSolversBase ~/.julia/packages/NLSolversBase/kavn7/src/interface.jl:124
  [9] value_jacobian!!
    @ ~/.julia/packages/NLSolversBase/kavn7/src/interface.jl:122 [inlined]
 [10] trust_region_(df::NLSolversBase.OnceDifferentiable{…}, initial_x::Vector{…}, xtol::Float64, ftol::Float64, iterations::Int64, store_trace::Bool, show_trace::Bool, extended_trace::Bool, factor::Float64, autoscale::Bool, cache::NLsolve.NewtonTrustRegionCache{…})
    @ NLsolve ~/.julia/packages/NLsolve/gJL1I/src/solvers/trust_region.jl:119
 [11] trust_region (repeats 2 times)
    @ ~/.julia/packages/NLsolve/gJL1I/src/solvers/trust_region.jl:235 [inlined]
 [12] nlsolve(df::NLSolversBase.OnceDifferentiable{…}, initial_x::Vector{…}; method::Symbol, xtol::Float64, ftol::Float64, iterations::Int64, store_trace::Bool, show_trace::Bool, extended_trace::Bool, linesearch::LineSearches.Static, linsolve::NLsolve.var"#27#29", factor::Float64, autoscale::Bool, m::Int64, beta::Int64, aa_start::Int64, droptol::Float64)
    @ NLsolve ~/.julia/packages/NLsolve/gJL1I/src/nlsolve/nlsolve.jl:26
 [13] nlsolve
    @ ~/.julia/packages/NLsolve/gJL1I/src/nlsolve/nlsolve.jl:1 [inlined]
 [14] nlsolve(f::Function, initial_x::Vector{…}; method::Symbol, autodiff::Symbol, inplace::Bool, kwargs::@Kwargs{…})
    @ NLsolve ~/.julia/packages/NLsolve/gJL1I/src/nlsolve/nlsolve.jl:52
 [15] nlsolve
    @ ~/.julia/packages/NLsolve/gJL1I/src/nlsolve/nlsolve.jl:40 [inlined]
 [16] find_steady_state!(s::KPS4{…}; prn::Bool, delta::Float64, stiffness_factor::Float64, upwind_dir::Float64)
    @ KiteModels ~/repos/KiteModels.jl/src/KPS4.jl:679
 [17] find_steady_state!
    @ ~/repos/KiteModels.jl/src/KPS4.jl:644 [inlined]
 [18] init_sim!(s::KPS4{…}; t_end::Float64, stiffness_factor::Float64, delta::Float64, upwind_dir::Float64, prn::Bool)
    @ KiteModels ~/repos/KiteModels.jl/src/KiteModels.jl:542
 [19] top-level scope
    @ REPL[11]:1
Some type information was truncated. Use `show(err)` to see complete types.

```

Any idea what could be the reason? Could it be due to some updated package version?

What is the meaning of ReadOnlyMemoryError in the first place?

---

<div class="post-metadata">

### Author: ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)
#### Post date: [January 14, 2025, 1:47pm UTC](https://discourse.julialang.org/t/trying-to-debug-readonlymemoryerror/124763/2 "2025-01-14T13:47:57Z")

</div>

I have no idea about the specific reason, but according to [this](https://www.jlhub.com/julia/manual/en/function/ReadOnlyMemoryError), the `ReadOnlyMemoryError()` is raised when “an operation tried to write to memory that is read-only”.

---

<div class="post-metadata">

### Author: ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)
#### Post date: [January 14, 2025, 2:04pm UTC](https://discourse.julialang.org/t/trying-to-debug-readonlymemoryerror/124763/3 "2025-01-14T14:04:06Z")

</div>

You are not alone:

> <https://github.com/JuliaMath/Dierckx.jl/issues/98>
>
> trying a simple \`ParametricSpline\` example errors with \`ReadOnlyMemoryError\`:
> \`…\`\`julia
> \_ \_ \_(\_)\_ | Documentation: https://docs.julialang.org
> (\_) | (\_) (\_) |
> \_ \_ \_| |\_ \_\_ \_ | Type "?" for help, "\]?" for Pkg help.
> | | | | | | |/ \_\` | |
> | | |\_| | | | (\_| | | Version 1.11.2 (2024-12-01)
> \_/ |\\\_\_'\_|\_|\_|\\\_\_'\_| | Official https://julialang.org/ release
> |\_\_/ |
> 
> (@v1.11) pkg\> activate --temp
> Activating new project at \`/tmp/jl\_Yywwx7\`
> 
> (jl\_Yywwx7) pkg\> add Dierckx
> Resolving package versions...
> Updating \`/tmp/jl\_Yywwx7/Project.toml\`
> \[39dd38d3\] + Dierckx v0.5.3
> Updating \`/tmp/jl\_Yywwx7/Manifest.toml\`
> \[39dd38d3\] + Dierckx v0.5.3
> \[692b3bcd\] + JLLWrappers v1.7.0
> \[21216c6a\] + Preferences v1.4.3
> \[cd4c43a9\] + Dierckx\_jll v0.1.1+0
> \[56f22d72\] + Artifacts v1.11.0
> \[ade2ca70\] + Dates v1.11.0
> \[8f399da3\] + Libdl v1.11.0
> \[de0858da\] + Printf v1.11.0
> \[fa267f1f\] + TOML v1.0.3
> \[4ec0a83e\] + Unicode v1.11.0
> \[e66e0078\] + CompilerSupportLibraries\_jll v1.1.1+0
> Precompiling project...
> 1 dependency successfully precompiled in 1 seconds. 8 already precompiled.
> 
> julia\> using Dierckx
> 
> julia\> X = rand(2, 10)
> 2×10 Matrix{Float64}:
> 0.249525 0.467703 0.588399 0.874943 0.971398 0.790435 0.969108 0.0201033 0.708681 0.3892
> 0.369256 0.823229 0.21343 0.267268 0.498935 0.667902 0.981211 0.739794 0.411529 0.633819
> 
> julia\> spl = ParametricSpline(X)
> ParametricSpline(knots=\[0.0,0.255327 … 0.738611,1.0\] (8 elements), k=3, extrapolation="nearest", residual=0.0)
> 
> julia\> spl(2)
> ERROR: ReadOnlyMemoryError()
> Stacktrace:
> \[1\] \_evaluate(t::Vector{Float64}, c::Vector{Float64}, k::Int64, x::Int64, bc::Int64)
> @ Dierckx ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:279
> \[2\] (::Dierckx.var"#13#14"{Vector{Float64}, Int64, Int64, Int64})(v::Vector{Float64})
> @ Dierckx ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:583
> \[3\] mapslices(f::Dierckx.var"#13#14"{Vector{Float64}, Int64, Int64, Int64}, A::Matrix{Float64}; dims::Vector{Int64})
> @ Base ./abstractarray.jl:3281
> \[4\] \_evaluate(t::Vector{Float64}, c::Matrix{Float64}, k::Int64, x::Int64, bc::Int64)
> @ Dierckx ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:581
> \[5\] evaluate
> @ ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:590 \[inlined\]
> \[6\] (::ParametricSpline)(x::Int64)
> @ Dierckx ~/.julia/packages/Dierckx/TDOyl/src/Dierckx.jl:1114
> \[7\] top-level scope
> @ REPL\[6\]:1
> \`\`\`
> I should mention that testing Dierckx also fails with \`ReadOnlyMemoryError\`.

> Downgrading to v0.1.0 of Dierckx\_jll fixes this issue.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [January 14, 2025, 2:55pm UTC](https://discourse.julialang.org/t/trying-to-debug-readonlymemoryerror/124763/4 "2025-01-14T14:55:47Z")

</div>

If someone wanted to fix the issue, I left some hints at [ReadOnlyMemoryError · Issue #98 · JuliaMath/Dierckx.jl · GitHub](https://github.com/JuliaMath/Dierckx.jl/issues/98#issuecomment-2590139412). Looks pretty easy to do for someone motivated
