# MethodError: no method matching unsafe\_convert(::Type{Ptr{Int32}}, ::Base.RefValue{Int64})

**URL:** <https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [July 2, 2020, 10:39am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424 "2020-07-02T10:39:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [July 2, 2020, 10:39am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/1 "2020-07-02T10:39:18Z")

</div>

Hello,

I have an error occur while running an ODE. It didn’t error 3-4 days ago, and I think `DifferentialEquations.jl` and `Sundails.jl` had an update in the meantime, so I will need to adjust my code. I think the error is coming from `Sundials` based on

```julia
MethodError: no method matching unsafe_convert(::Type{Ptr{Int32}}, ::Base.RefValue{Int64})
Closest candidates are:
  unsafe_convert(!Matched::Type{Ptr{Nothing}}, ::Base.RefValue{T}) where T at refvalue.jl:30
  unsafe_convert(::Type{T}, !Matched::T) where T<:Ptr at essentials.jl:393
  unsafe_convert(::Type{P}, !Matched::Ptr) where P<:Ptr at essentials.jl:394
  ...
in top-level scope at Creating clearance graphs.jl:58
in collect at base\array.jl:665
in iterate at base\generator.jl:47 
in #112 at base\none 
in run_one_foodweb_no_pristine at test for clearance comparison error.jl:113
in collect at base\array.jl:665
in iterate at base\generator.jl:47 
in at base\none
in apply_clearance at test for clearance comparison error.jl:79
in at DiffEqBase\gzrxg\src\solve.jl:104
in #solve#453 at DiffEqBase\gzrxg\src\solve.jl:106 
in solve_up##kw at DiffEqBase\gzrxg\src\solve.jl:110 
in #solve_up#454 at DiffEqBase\gzrxg\src\solve.jl:116
in solve_call##kw at DiffEqBase\gzrxg\src\solve.jl:69 
in #solve_call#450 at DiffEqBase\gzrxg\src\solve.jl:96
in at Sundials\mWUX7\src\common_interface\solve.jl:10
in __solve##kw at Sundials\mWUX7\src\common_interface\solve.jl:10 
in __solve##kw at Sundials\mWUX7\src\common_interface\solve.jl:10 
in __solve##kw at Sundials\mWUX7\src\common_interface\solve.jl:10 
in __solve##kw at Sundials\mWUX7\src\common_interface\solve.jl:10 
in #__solve#22 at Sundials\mWUX7\src\common_interface\solve.jl:12
in solve! at Sundials\mWUX7\src\common_interface\solve.jl:1190
in get_iters! at Sundials\mWUX7\src\common_interface\solve.jl:1159
in CVodeGetNumSteps at Sundials\mWUX7\src\API\cvodes.jl:188

```

I don’t know what is being converted that is unsafe. I also don’t know how to make a MWE for this as I use a few files to define what goes into the differential equation. Is there anything obvious? Alternatively, is there a way to revert to a previous version of `Sundials` or `DifferentialEquations`?

```julia
function apply_clearance(bioS, clearance_V_type, target_species)

    p = (D, S, K, v, r, X, num_nutrient, num_plant, num_animal, num_vessel_types, bm, foodWeb, b, q, ω, c, h, e, target_species, catch_max, b0V, μ, elasticity, clearance_V_type)

    function condition(out, u, t, integrator)
        out .= bioS[1:(end-1)] .- 1e-6
    end

    function affect!(integrator, event_index)
        integrator.bioS[event_index] = 0.0
    end

   extinction_cb = VectorContinuousCallback(condition,affect!,length(bioS[1:(end-1)]))

    fishing_prob = ODEProblem(dBdT,bioS,tspan,p)
    fishing_sol = solve(fishing_prob, save_everystep=false, alg = CVODE_BDF(), abstol=1e-6,reltol=1e-3, callback=extinction_cb)

end

```

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [July 2, 2020, 11:21am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/2 "2020-07-02T11:21:39Z")

</div>

You can install certain versions of packages by entering the PKG mode (pressing `]`)  
and entering e.g.,

```julia
add Sundials@4.2.3

```

To see which versions are available it is helpful to look at the corresponding github page (googling the package name and adding `.jl` ).  
On a more personal note: I would strongly advice organizing your work into environments, projects, and packages. Doing so would alleviates such versioning problems.  
For a start you can have a look here:  
[https://julialang.github.io/Pkg.jl/v1/getting-started/](https://julialang.github.io/Pkg.jl/v1/getting-started/)  
or as it seems that you are doing science maybe have a look here:

> **[GitHub - JuliaDynamics/DrWatson.jl: The perfect sidekick to your scientific...](https://github.com/JuliaDynamics/DrWatson.jl)**
>
> The perfect sidekick to your scientific inquiries. Contribute to JuliaDynamics/DrWatson.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 2, 2020, 11:33am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/3 "2020-07-02T11:33:00Z")

</div>

It’s a bug in Sundails.jl on windows. [https://github.com/SciML/Sundials.jl/blob/66a733a3d2064f43177337986afb07df5d72fea5/src/common\_interface/solve.jl#L1170](https://github.com/SciML/Sundials.jl/blob/66a733a3d2064f43177337986afb07df5d72fea5/src/common_interface/solve.jl#L1170) introduced in [https://github.com/SciML/Sundials.jl/pull/270/commits/b0578dc2da3399633c4e4cfb5ec437d66979815d](https://github.com/SciML/Sundials.jl/pull/270/commits/b0578dc2da3399633c4e4cfb5ec437d66979815d) assumes that `Clong` is `Int`, which is not true on windows 64bit.

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [July 2, 2020, 1:07pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/4 "2020-07-02T13:07:36Z")

</div>

@Rudi79 Thank you for your reply.

Reverting to the previous version of `Sundials.jl` or `DiffEqBase.jl` does not prevent the error from happening, which means something else is causing the issue.

I will look into `DrWatson.jl` as you are the second person to recommend it to me.

@yuyichao Thank you for your reply. Sometimes it’s nice to learn it is a code issue, and not something one has done 🙂 Is there a way around this bug?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 2, 2020, 1:16pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/5 "2020-07-02T13:16:53Z")

</div>

Submit a private and fix it. It’s a trivial fix and you can find other correct way to do it by just searching Ref in that file.

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [July 2, 2020, 1:29pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/6 "2020-07-02T13:29:17Z")

</div>

I don’t understand what is meant by submit private.

I found `Ref` in the link you provided. I assume you mean this part of the code?

```julia
function DiffEqBase.solve!(integrator::AbstractSundialsIntegrator)
    uType = eltype(integrator.sol.u)
    iters = Ref(-1)
    while !isempty(integrator.opts.tstops)

```

but I don’t know what to do or how I would access that line of code within my computer. I am a really basic programmer.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 2, 2020, 2:14pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/7 "2020-07-02T14:14:27Z")

</div>

I mean a pr  
And I meant changing it to match other ref in the same file…

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [July 2, 2020, 2:28pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/8 "2020-07-02T14:28:21Z")

</div>

I’m sorry, I still don’t understand what is meant by pr.

So I should change `Ref(Clong(-1))` to `Ref(Int(-1))` ?

---

<div class="post-metadata">

**Author:** ![YingboMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yingboma/32/2181_2.png) [@YingboMa](https://discourse.julialang.org/u/YingboMa)\
**Post date:** [July 2, 2020, 6:38pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/9 "2020-07-02T18:38:02Z")

</div>

I made a new release with the fix. Could you update?

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [July 3, 2020, 8:40am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-unsafe-convert-type-ptr-int32-base-refvalue-int64/42424/10 "2020-07-03T08:40:03Z")

</div>

It works! Thanks!
