Makie - Colorbar crashing saving figure

Hi, I am using Makie for displaying finite element computations with Gridap.jl. Works fine with GLMakie, but the use of “colorbar” crashes with CairoMakie (with exactly the same code as for GLMakie). Any clue ?

Can you post an MWE that reproduces the error?

ERROR: LoadError: MethodError: no method matching interpolated_getindex(::Vector{ColorTypes.RGB{Float32}}, ::Float64, ::Vector{Float64})
Closest candidates are:
interpolated_getindex(::AbstractArray{T, N} where N, ::AbstractFloat) where T at /home/herve/.julia/packages/Makie/NL7Xw/src/colorsampler.jl:48
interpolated_getindex(::AbstractArray, ::Number, ::Union{Tuple{Vararg{T, N}}, StaticArrays.StaticVector{N, T}} where {N, T}) at /home/herve/.julia/packages/Makie/NL7Xw/src/colorsampler.jl:34
Stacktrace:
[1] (::CairoMakie.var"#17#20"{Vector{ColorTypes.RGB{Float32}}, Vector{Float64}, Nothing, Nothing, Nothing, Float64, Float64})(c::Float64)
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/utils.jl:222
[2] iterate
@ ./generator.jl:47 [inlined]
[3] _collect
@ ./array.jl:695 [inlined]
[4] collect_similar
@ ./array.jl:606 [inlined]
[5] map
@ ./abstractarray.jl:2294 [inlined]
[6] per_face_colors(color::Vector{Float64}, colormap::Vector{ColorTypes.RGB{Float32}}, colorrange::Vector{Float64}, matcap::Nothing, vertices::Vector{GeometryBasics.Point{2, Float32}}, faces::Vector{GeometryBasics.TriangleFace{T} where T}, normals::Nothing, uv::Nothing, lowclip::Nothing, highclip::Nothing, nan_color::Nothing)
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/utils.jl:214
[7] per_face_colors(color::Vector{Float64}, colormap::Vector{ColorTypes.RGB{Float32}}, colorrange::Vector{Float64}, matcap::Nothing, vertices::Vector{GeometryBasics.Point{2, Float32}}, faces::Vector{GeometryBasics.TriangleFace{T} where T}, normals::Nothing, uv::Nothing)
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/utils.jl:198
[8] draw_mesh2D(scene::Scene, screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, primitive::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.Ngon{2, Float32, 3, GeometryBasics.Point{2, Float32}}, GeometryBasics.SimpleFaceView{2, Float32, 3, GeometryBasics.OffsetInteger{-1, UInt32}, GeometryBasics.Point{2, Float32}, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/primitives.jl:636
[9] draw_atomic(scene::Scene, screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, primitive::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.Ngon{2, Float32, 3, GeometryBasics.Point{2, Float32}}, GeometryBasics.SimpleFaceView{2, Float32, 3, GeometryBasics.OffsetInteger{-1, UInt32}, GeometryBasics.Point{2, Float32}, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/primitives.jl:611
[10] draw_plot(scene::Scene, screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, primitive::Mesh{Tuple{GeometryBasics.Mesh{2, Float32, GeometryBasics.Ngon{2, Float32, 3, GeometryBasics.Point{2, Float32}}, GeometryBasics.SimpleFaceView{2, Float32, 3, GeometryBasics.OffsetInteger{-1, UInt32}, GeometryBasics.Point{2, Float32}, GeometryBasics.NgonFace{3, GeometryBasics.OffsetInteger{-1, UInt32}}}}}})
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/infrastructure.jl:240
[11] draw_plot(scene::Scene, screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, primitive::Mesh{Tuple{GridapMakie.PlotGrid{Gridap.Visualization.VisualizationGrid{2, 2}}}}) (repeats 2 times)
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/infrastructure.jl:244
[12] cairo_draw(screen::CairoMakie.CairoScreen{Cairo.CairoSurfaceBase{UInt32}}, scene::Scene)
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/infrastructure.jl:173
[13] backend_show(x::CairoMakie.CairoBackend, io::IOContext{IOStream}, #unused#::MIME{Symbol(“image/png”)}, scene::Scene)
@ CairoMakie ~/.julia/packages/CairoMakie/0yMYf/src/infrastructure.jl:339
[14] show(io::IOContext{IOStream}, m::MIME{Symbol(“image/png”)}, scene::Scene; update::Bool)
@ Makie ~/.julia/packages/Makie/NL7Xw/src/display.jl:113
[15] (::Makie.var"#914#915"{Float64, Float64, Bool, DataType, Scene})(s::IOStream)
@ Makie ~/.julia/packages/Makie/NL7Xw/src/display.jl:252
[16] open(::Makie.var"#914#915"{Float64, Float64, Bool, DataType, Scene}, ::String, ::Vararg{String, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base ./io.jl:330
[17] open
@ ./io.jl:328 [inlined]
[18] save(file::File{DataFormat{:PNG}, String}, fig::Figure; resolution::Tuple{Int64, Int64}, pt_per_unit::Float64, px_per_unit::Float64, update::Bool)
@ Makie ~/.julia/packages/Makie/NL7Xw/src/display.jl:246
[19] save(file::File{DataFormat{:PNG}, String}, fig::Figure)
@ Makie ~/.julia/packages/Makie/NL7Xw/src/display.jl:228
[20] save(filename::String, fig::Figure; args::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Makie ~/.julia/packages/Makie/NL7Xw/src/display.jl:218
[21] save(filename::String, fig::Figure)
@ Makie ~/.julia/packages/Makie/NL7Xw/src/display.jl:218
[22] top-level scope
@ ~/Workspace/Julia/FP_test_1.jl:138
in expression starting at /home/herve/Workspace/Julia/FP_test_1.jl:138

MWE means minimal reproducable example.
So short piece of code, that we can try and run to fix the bug.

Code example: it’s a modification of a tutorial example.

using Gridap, GridapMakie
using CairoMakie
using FileIO

domain = (0, 1, 0, 1)
cell_nums = (10, 10)
model = CartesianDiscreteModel(domain, cell_nums) |> simplexify

Ω = Triangulation(model)
reffe = ReferenceFE(lagrangian, Float64, 1)
V = FESpace(model, reffe)
uh = interpolate(x->sin(π*(x[1]+x[2])), V)

fig, _, plt = plot(Ω, uh, colormap=:thermal, colorrange=[0, 4.])
wireframe!(Ω)#, color=:gray, linewidth=0.5)
Colorbar(fig[1,2], plt)
save("test_cairo.png", fig)

colorrange=[0, 4.]

try colorrange=(0, 4)

Works much better. Thank you !

Note: it does not crash with GLMakie instead of CairoMakie…