Different behaviour between CairoMakie and GLMakie

Hi all,

I am confused since a couple of days, because GLMakie and CairoMakie have a different behavior. Here is the MWE:

``````using CairoMakie
# using GLMakie

x = range(0., 2π, 100)
z = sin.(x)

x = range(0., 2π, 100)
z = sin.(x)
zmin = minimum(z)

lower = [Point3f(x[i], 1, zmin) for i in eachindex(x)]
upper = [Point3f(x[i], 1., z[i]) for i in eachindex(x)]
edge_start = [Point3f(x[1], 1., zmin), Point3f(x[1], 1., z[1])]
edge_end = [Point3f(x[end], 1., zmin), Point3f(x[end], 1., z[end])]

fig = Figure()
ax = Axis3(fig[1,1])
band!(ax, lower, upper, color = (:blue, 0.1))
lines!(ax, upper, color = z, colormap = :viridis)
lines!(ax, edge_start, color = [z[1], z[1]], colormap = :viridis)
lines!(ax, edge_end, color = [z[end], z[end]], colormap = :viridis)

fig # for plotting CairoMakie figure in VSCode
# display(fig) # When using GLMakie
``````

While this code works fine with `GLMakie`, it throws the following error when using `CairoMakie`: `Looking up a non-finite or NaN value in a colormap is undefined.`

After inspection, the problem comes from `lines!(ax, edge_start, color = [z[1], z[1]], colormap = :viridis)` and `lines!(ax, edge_end, color = [z[end], z[end]], colormap = :viridis)`, but I have to admit that I can’t explain why `GLMakie` and `CairoMakie` behave differently in this case.

``````versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 20 × Intel(R) Xeon(R) W-2255 CPU @ 3.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
Threads: 1 on 20 virtual cores
Environment:
JULIA_EDITOR = code
``````(@v1.8) pkg> st
They behave differently because the lookup is done by a shader on the GPU for GLMakie. The reason is that you’re passing a vector with twice the same value, so the automatic color range is computed as `(val, val)` so the range is `0` wide, which means that linear interpolation of the colormap fails. Pass the known min and max values manually as `colorrange = (min, max)` to avoid this.
Thanks @jules. I have just tried this code on my windows machine with `CairoMakie` and it works. On my windows machine, the version of `CairoMakie` is v0.10.2, while it is v0.7.5 on my Linux machine. I can’t access my Linux machine right now, but I will upgrade `CairoMakie` next week. I’ll keep you inform.