MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.38k stars 302 forks source link

DomainError when plotting on a Raspberry Pi #477

Closed yakir12 closed 4 weeks ago

yakir12 commented 4 years ago

This is on a RPI 4, with a hyperpixel screen attached (not that that would matter). I just thought that a DomainError is not ordinary.. Hope this helps. I'll keep trying.

julia> lines(rand(10))
[ Info: Caching fonts, this may take a while. Needed only on first run!
ERROR: DomainError with -3.25967296e8:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
 [2] sqrt at ./math.jl:493 [inlined]
 [3] sqrt at ./math.jl:519 [inlined]
 [4] _broadcast_getindex_evalf at ./broadcast.jl:625 [inlined]
 [5] _broadcast_getindex at ./broadcast.jl:598 [inlined]
 [6] _getindex at ./broadcast.jl:621 [inlined]
 [7] _broadcast_getindex at ./broadcast.jl:597 [inlined]
 [8] getindex at ./broadcast.jl:558 [inlined]
 [9] macro expansion at ./broadcast.jl:888 [inlined]
 [10] macro expansion at ./simdloop.jl:77 [inlined]
 [11] copyto! at ./broadcast.jl:887 [inlined]
 [12] copyto! at ./broadcast.jl:842 [inlined]
 [13] copy at ./broadcast.jl:818 [inlined]
 [14] materialize at ./broadcast.jl:798 [inlined]
 [15] sdf(::Array{Bool,2}) at /home/pi/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:63
 [16] sdf at /home/pi/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:64 [inlined]
 [17] sdistancefield(::Array{UInt8,2}, ::Int32, ::Int32) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:217
 [18] render(::AbstractPlotting.TextureAtlas, ::Char, ::Array{Ptr{FreeType.FT_FaceRec},1}, ::Int32, ::Int32) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:238
 [19] render at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:233 [inlined]
 [20] (::getfield(AbstractPlotting, Symbol("##49#50")){AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_FaceRec},1}})() at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:182
 [21] get!(::getfield(AbstractPlotting, Symbol("##49#50")){AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_FaceRec},1}}, ::Dict{Any,Int32}, ::Tuple{Char,Array{Ptr{FreeType.FT_FaceRec},1}}) at ./dict.jl:452
 [22] insert_glyph! at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:181 [inlined]
 [23] cached_load() at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:105
 [24] get_texture_atlas at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:130 [inlined]
 [25] plot!(::Annotations{...}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/basic_recipes.jl:398
 [26] plot!(::Axis2D{...}, ::Type{Annotations{...}}, ::Attributes, ::Array{String,1}, ::Array{Point{2,Float32},1}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:662
 [27] #annotations!#369 at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:24 [inlined]
 [28] #annotations! at ./none:0 [inlined]
 [29] #TextBuffer#599(::Array{Quaternion{Float32},1}, ::Array{ColorTypes.RGBA{Float32},1}, ::Array{Float32,1}, ::Array{Array{Ptr{FreeType.FT_FaceRec},1},1}, ::Array{Vec{2,Float32},1}, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(AbstractPlotting.TextBuffer), ::Axis2D{...}, ::Type{Point{2,T} where T}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/buffers.jl:55
 [30] TextBuffer(::Axis2D{...}, ::Type{Point{2,T} where T}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/buffers.jl:55
 [31] plot!(::Scene, ::Type{Axis2D{...}}, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/axis.jl:503
 [32] #axis2d!#609(::Base.Iterators.Pairs{Symbol,NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}},Tuple{Symbol},NamedTuple{(:ticks,),Tuple{NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}}}}}, ::typeof(axis2d!), ::Scene, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:38
 [33] (::getfield(AbstractPlotting, Symbol("#kw##axis2d!")))(::NamedTuple{(:ticks,),Tuple{NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}}}}, ::typeof(axis2d!), ::Scene, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at ./none:0
 [34] add_axis!(::Scene, ::Attributes) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:745
 [35] plot!(::Scene, ::Type{Lines{...}}, ::Attributes, ::Tuple{Observables.Observable{Array{Float64,1}}}, ::Observables.Observable{Tuple{Array{Point{2,Float32},1}}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:647
 [36] #plot!#208(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot!), ::Scene, ::Type{Lines{...}}, ::Attributes, ::Array{Float64,1}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:560
 [37] plot!(::Scene, ::Type{Lines{...}}, ::Attributes, ::Array{Float64,1}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:529
 [38] #lines#125(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(lines), ::Array{Float64,1}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:15
 [39] lines(::Array{Float64,1}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:13
 [40] top-level scope at REPL[11]:1
yakir12 commented 4 years ago

OK, it's happening with other plotting functions:

julia> using AbstractPlotting, GLMakie

julia> image(rand(RGBf0, 100, 100))
[ Info: Caching fonts, this may take a while. Needed only on first run!
ERROR: DomainError with -3.25967296e8:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
 [2] sqrt at ./math.jl:493 [inlined]
 [3] sqrt at ./math.jl:519 [inlined]
 [4] _broadcast_getindex_evalf at ./broadcast.jl:625 [inlined]
 [5] _broadcast_getindex at ./broadcast.jl:598 [inlined]
 [6] _getindex at ./broadcast.jl:621 [inlined]
 [7] _broadcast_getindex at ./broadcast.jl:597 [inlined]
 [8] getindex at ./broadcast.jl:558 [inlined]
 [9] macro expansion at ./broadcast.jl:888 [inlined]
 [10] macro expansion at ./simdloop.jl:77 [inlined]
 [11] copyto! at ./broadcast.jl:887 [inlined]
 [12] copyto! at ./broadcast.jl:842 [inlined]
 [13] copy at ./broadcast.jl:818 [inlined]
 [14] materialize at ./broadcast.jl:798 [inlined]
 [15] sdf(::Array{Bool,2}) at /home/pi/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:63
 [16] sdf at /home/pi/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:64 [inlined]
 [17] sdistancefield(::Array{UInt8,2}, ::Int32, ::Int32) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:217
 [18] render(::AbstractPlotting.TextureAtlas, ::Char, ::Array{Ptr{FreeType.FT_FaceRec},1}, ::Int32, ::Int32) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:238
 [19] render at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:233 [inlined]
 [20] (::getfield(AbstractPlotting, Symbol("##49#50")){AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_FaceRec},1}})() at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:182
 [21] get!(::getfield(AbstractPlotting, Symbol("##49#50")){AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_FaceRec},1}}, ::Dict{Any,Int32}, ::Tuple{Char,Array{Ptr{FreeType.FT_FaceRec},1}}) at ./dict.jl:452
 [22] insert_glyph! at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:181 [inlined]
 [23] cached_load() at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:105
 [24] get_texture_atlas at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:130 [inlined]
 [25] plot!(::Annotations{...}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/basic_recipes.jl:398
 [26] plot!(::Axis2D{...}, ::Type{Annotations{...}}, ::Attributes, ::Array{String,1}, ::Array{Point{2,Float32},1}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:662
 [27] #annotations!#369 at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:24 [inlined]
 [28] #annotations! at ./none:0 [inlined]
 [29] #TextBuffer#599(::Array{Quaternion{Float32},1}, ::Array{ColorTypes.RGBA{Float32},1}, ::Array{Float32,1}, ::Array{Array{Ptr{FreeType.FT_FaceRec},1},1}, ::Array{Vec{2,Float32},1}, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(AbstractPlotting.TextBuffer), ::Axis2D{...}, ::Type{Point{2,T} where T}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/buffers.jl:55
 [30] TextBuffer(::Axis2D{...}, ::Type{Point{2,T} where T}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/buffers.jl:55
 [31] plot!(::Scene, ::Type{Axis2D{...}}, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/axis.jl:503
 [32] #axis2d!#609(::Base.Iterators.Pairs{Symbol,NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}},Tuple{Symbol},NamedTuple{(:ticks,),Tuple{NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}}}}}, ::typeof(axis2d!), ::Scene, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:38
 [33] (::getfield(AbstractPlotting, Symbol("#kw##axis2d!")))(::NamedTuple{(:ticks,),Tuple{NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}}}}, ::typeof(axis2d!), ::Scene, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at ./none:0
 [34] add_axis!(::Scene, ::Attributes) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:745
 [35] plot!(::Scene, ::Type{Image{...}}, ::Attributes, ::Tuple{Observables.Observable{Array{ColorTypes.RGB{Float32},2}}}, ::Observables.Observable{Tuple{IntervalSets.Interval{:closed,:closed,Float32},IntervalSets.Interval{:closed,:closed,Float32},Array{ColorTypes.RGB{Float32},2}}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:647
 [36] #plot!#208(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot!), ::Scene, ::Type{Image{...}}, ::Attributes, ::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:560
 [37] plot!(::Scene, ::Type{Image{...}}, ::Attributes, ::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:529
 [38] #image#93(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(image), ::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:15
 [39] image(::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:13
 [40] top-level scope at REPL[2]:1
SimonDanisch commented 4 years ago

Hm weird, it happens here: https://github.com/JuliaGraphics/SignedDistanceFields.jl/blob/master/src/SignedDistanceFields.jl#L63 I can hardly believe, that this code is platform specific... It does get fed with an image rendered by FreeType, which might be a bit platform specific...

As a work around, you can copy the files at AbstractPlotting.get_cache_path() from your PC that has a working Makie install, to the raspberry pie!

If you want to debug this, you could try to see if anything weird happens here:

using FreeTypeAbstraction, SignedDistanceFields
#select_font_face(cc, font)
glyph = 'x'
DF = 50
downsample  = 5
font = [findfont("arial")]
bitmap, extent = renderface(font, glyph, (DF*downsample, DF*downsample))
w, h = size(bitmap)
in_or_out = bitmap .> 0.5 .* 255
sd = sdf(in_or_out)
yakir12 commented 4 years ago

Reporting back what I get:

(v1.2) pkg> add FreeTypeAbstraction SignedDistanceFields
 Resolving package versions...
 Installed DataStructures ─ v0.17.6
  Updating `~/.julia/environments/v1.2/Project.toml`
  [663a7486] + FreeTypeAbstraction v0.4.2
  [73760f76] + SignedDistanceFields v0.4.0
  Updating `~/.julia/environments/v1.2/Manifest.toml`
  [864edb3b] ↑ DataStructures v0.17.5 ⇒ v0.17.6

julia> using FreeTypeAbstraction, SignedDistanceFields
[ Info: Recompiling stale cache file /home/pi/.julia/compiled/v1.2/FreeTypeAbstraction/Qde7d.ji for FreeTypeAbstraction [663a7486-cb36-511b-a19d-713bb74d65c9]

julia> #select_font_face(cc, font)
       glyph = 'x'
'x': ASCII/Unicode U+0078 (category Ll: Letter, lowercase)

julia> DF = 50
50

julia> downsample  = 5
5

julia> font = [findfont("arial")]
1-element Array{Nothing,1}:
 nothing

julia> bitmap, extent = renderface(font, glyph, (DF*downsample, DF*downsample))
ERROR: MethodError: no method matching unsafe_convert(::Type{Ptr{FreeType.FT_FaceRec}}, ::Nothing)
Closest candidates are:
  unsafe_convert(::Type{T<:Ptr}, ::T<:Ptr) where T<:Ptr at essentials.jl:394
  unsafe_convert(::Type{P<:Ptr}, ::Ptr) where P<:Ptr at essentials.jl:395
  unsafe_convert(::Type{Ptr{T}}, ::Array{T,N} where N) where T at pointer.jl:65
  ...
Stacktrace:
 [1] FT_Set_Pixel_Sizes(::Nothing, ::UInt32, ::UInt32) at /home/pi/.julia/packages/FreeType/2dE5w/gen/api/ft_api.jl:57
 [2] setpixelsize(::Array{Nothing,1}, ::Tuple{Int32,Int32}) at /home/pi/.julia/packages/FreeTypeAbstraction/dlDGC/src/functions.jl:105
 [3] renderface(::Array{Nothing,1}, ::Char, ::Tuple{Int32,Int32}) at /home/pi/.julia/packages/FreeTypeAbstraction/dlDGC/src/functions.jl:126
 [4] top-level scope at REPL[8]:1
SimonDanisch commented 4 years ago

Ah, you don't have that font... Try one, that actually exists :D

yakir12 commented 4 years ago

Right, now this:

julia> font = [findfont("helvetica")]
1-element Array{Ptr{FreeType.FT_FaceRec},1}:
 Ptr{FreeType.FT_FaceRec} @0x028ccc28

julia> bitmap, extent = renderface(font, glyph, (DF*downsample, DF*downsample))
ERROR: Couldn't set the pixel size for font with error 23
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] setpixelsize at /home/pi/.julia/packages/FreeTypeAbstraction/dlDGC/src/functions.jl:107 [inlined]
 [3] renderface(::Array{Ptr{FreeType.FT_FaceRec},1}, ::Char, ::Tuple{Int32,Int32}) at /home/pi/.julia/packages/FreeTypeAbstraction/dlDGC/src/functions.jl:126
 [4] top-level scope at REPL[14]:1
yakir12 commented 4 years ago

BTW, I copied all the files in the folder where AbstractPlotting.get_cache_path() was to the RPI, but I got the exact same error, probably because it tried cashing the fonts nevertheless... I'll add that I needed to create the relevant path, namely makiegallery/.cache on the RPI because it was missing. Not sure if that's telling or irrelevant.

julia> using AbstractPlotting, GLMakie
[ Info: Recompiling stale cache file /home/pi/.julia/compiled/v1.2/AbstractPlotting/6fydZ.ji for AbstractPlotting [537997a7-5e4e-5d89-9595-2241ea00577e]
[ Info: Recompiling stale cache file /home/pi/.julia/compiled/v1.2/GLMakie/nfnZR.ji for GLMakie [e9467ef8-e4e7-5192-8a1a-b1aee30e663a]

julia> image(rand(RGBf0, 100, 100))
[ Info: You can likely ignore the following warning, if you just switched Julia versions for GLVisualize
┌ Warning: TypeError(:Vararg, "count", Int32, 4)
└ @ AbstractPlotting ~/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:98
[ Info: Caching fonts, this may take a while. Needed only on first run!
ERROR: DomainError with -3.25967296e8:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
SimonDanisch commented 4 years ago

Well, I don't know why that complains :D But that shouldn't be the original problem, since it's erroring after that... Try another font? You can also use newface(path_to_font)... So e.g.:

font = newface(AbstractPlotting.assetpath("fonts", "DejaVuSans.ttf"))

That should use the same font as AbstractPlotting...

yakir12 commented 4 years ago

OK, that passed through, so running:

using FreeTypeAbstraction, SignedDistanceFields, AbstractPlotting
#select_font_face(cc, font)
glyph = 'x'
DF = 50
downsample  = 5
font = newface(AbstractPlotting.assetpath("fonts", "DejaVuSans.ttf"))
bitmap, extent = renderface(font, glyph, (DF*downsample, DF*downsample))
w, h = size(bitmap)
in_or_out = bitmap .> 0.5 .* 255
sd = sdf(in_or_out)

doesn't through any errors. Let me know if I should try anything else.

As to the method of copying the fonts over to the cache folder, yea, still stuck there, not sure how to let know GLMakie not to try caching the fonts.

SimonDanisch commented 4 years ago

Hm as soon as the files are there it shouldn't try caching! Maybe you have a version mismatch?

yakir12 commented 4 years ago

Now they have the same versions (I had Makie on the PC, but removed that and switched to GLMakie, hm, maybe I should delete the fonts cache to force it to rewrite them?).

On PC:

(v1.2) pkg> st
    Status `~/.julia/environments/v1.2/Project.toml`
  [537997a7] AbstractPlotting v0.9.10
  [e9467ef8] GLMakie v0.0.8

on RPI:

(v1.2) pkg> st
    Status `~/.julia/environments/v1.2/Project.toml`
  [537997a7] AbstractPlotting v0.9.10
  [e9467ef8] GLMakie v0.0.8

and still the same domain error.

OK, I'll try erasing all the caches, see where that takes me

SimonDanisch commented 4 years ago

It needs to come from an AbstractPlotting install, that already run the caching :P And then you should copy the whole folder at .julia/makiegallery/.cache

SimonDanisch commented 4 years ago

Check on the pi, that isfile(get_cache_path()) returns true ;)

yakir12 commented 4 years ago

isfile(AbstractPlotting.get_cache_path()) return true:

julia> isfile(AbstractPlotting.get_cache_path())
true

julia> image(rand(RGBf0, 10,10))
[ Info: You can likely ignore the following warning, if you just switched Julia versions for GLVisualize
┌ Warning: TypeError(:Vararg, "count", Int32, 4)
└ @ AbstractPlotting ~/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:98
[ Info: Caching fonts, this may take a while. Needed only on first run!
ERROR: DomainError with -3.25967296e8:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(::Symbol, ::Float64) at ./math.jl:31
 [2] sqrt at ./math.jl:493 [inlined]
 [3] sqrt at ./math.jl:519 [inlined]
 [4] _broadcast_getindex_evalf at ./broadcast.jl:625 [inlined]
 [5] _broadcast_getindex at ./broadcast.jl:598 [inlined]
 [6] _getindex at ./broadcast.jl:621 [inlined]
 [7] _broadcast_getindex at ./broadcast.jl:597 [inlined]
 [8] getindex at ./broadcast.jl:558 [inlined]
 [9] macro expansion at ./broadcast.jl:888 [inlined]
 [10] macro expansion at ./simdloop.jl:77 [inlined]
 [11] copyto! at ./broadcast.jl:887 [inlined]
 [12] copyto! at ./broadcast.jl:842 [inlined]
 [13] copy at ./broadcast.jl:818 [inlined]
 [14] materialize at ./broadcast.jl:798 [inlined]
 [15] sdf(::Array{Bool,2}) at /home/pi/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:63
 [16] sdf at /home/pi/.julia/packages/SignedDistanceFields/RNoSO/src/SignedDistanceFields.jl:64 [inlined]
 [17] sdistancefield(::Array{UInt8,2}, ::Int32, ::Int32) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:217
 [18] render(::AbstractPlotting.TextureAtlas, ::Char, ::Array{Ptr{FreeType.FT_FaceRec},1}, ::Int32, ::Int32) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:238
 [19] render at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:233 [inlined]
 [20] (::getfield(AbstractPlotting, Symbol("##49#50")){AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_FaceRec},1}})() at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:182
 [21] get!(::getfield(AbstractPlotting, Symbol("##49#50")){AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_FaceRec},1}}, ::Dict{Any,Int32}, ::Tuple{Char,Array{Ptr{FreeType.FT_FaceRec},1}}) at ./dict.jl:452
 [22] insert_glyph! at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:181 [inlined]
 [23] cached_load() at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:105
 [24] get_texture_atlas at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:130 [inlined]
 [25] plot!(::Annotations{...}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/basic_recipes.jl:398
 [26] plot!(::Axis2D{...}, ::Type{Annotations{...}}, ::Attributes, ::Array{String,1}, ::Array{Point{2,Float32},1}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:662
 [27] #annotations!#369 at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:24 [inlined]
 [28] #annotations! at ./none:0 [inlined]
 [29] #TextBuffer#599(::Array{Quaternion{Float32},1}, ::Array{ColorTypes.RGBA{Float32},1}, ::Array{Float32,1}, ::Array{Array{Ptr{FreeType.FT_FaceRec},1},1}, ::Array{Vec{2,Float32},1}, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(AbstractPlotting.TextBuffer), ::Axis2D{...}, ::Type{Point{2,T} where T}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/buffers.jl:55
 [30] TextBuffer(::Axis2D{...}, ::Type{Point{2,T} where T}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/buffers.jl:55
 [31] plot!(::Scene, ::Type{Axis2D{...}}, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/basic_recipes/axis.jl:503
 [32] #axis2d!#609(::Base.Iterators.Pairs{Symbol,NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}},Tuple{Symbol},NamedTuple{(:ticks,),Tuple{NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}}}}}, ::typeof(axis2d!), ::Scene, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:38
 [33] (::getfield(AbstractPlotting, Symbol("#kw##axis2d!")))(::NamedTuple{(:ticks,),Tuple{NamedTuple{(:ranges, :labels),Tuple{AbstractPlotting.Automatic,AbstractPlotting.Automatic}}}}, ::typeof(axis2d!), ::Scene, ::Attributes, ::Observables.Observable{GeometryTypes.HyperRectangle{3,Float32}}) at ./none:0
 [34] add_axis!(::Scene, ::Attributes) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:745
 [35] plot!(::Scene, ::Type{Image{...}}, ::Attributes, ::Tuple{Observables.Observable{Array{ColorTypes.RGB{Float32},2}}}, ::Observables.Observable{Tuple{IntervalSets.Interval{:closed,:closed,Float32},IntervalSets.Interval{:closed,:closed,Float32},Array{ColorTypes.RGB{Float32},2}}}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:647
 [36] #plot!#208(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot!), ::Scene, ::Type{Image{...}}, ::Attributes, ::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:560
 [37] plot!(::Scene, ::Type{Image{...}}, ::Attributes, ::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/interfaces.jl:529
 [38] #image#93(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(image), ::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:15
 [39] image(::Array{ColorTypes.RGB{Float32},2}) at /home/pi/.julia/packages/AbstractPlotting/B5nOF/src/recipes.jl:13
 [40] top-level scope at REPL[6]:1
SimonDanisch commented 4 years ago

Did you switch between julia versions? Seems like deserialization fails...

yakir12 commented 4 years ago

Oh, wait, of course, I mean, my PC runs the generic 64 bit julia, the pi runs the arm 32 ones...

yakir12 commented 4 years ago

Thanks a lot @SimonDanisch for all the help. Do any further ideas in this..?

yakir12 commented 4 years ago

So this might be obvious but, I tried to deserialize the cache on the pi, after copying it over. And it failed cause it was created on the PC which of course is 64 bit:

using FreeTypeAbstraction, SignedDistanceFields, AbstractPlotting

julia> a = deserialize(".julia/makiegallery/.cache/texture_atlas_high.jls")

Is there anything else I can try via fixing the domain error? Or is the only way forward to get my hand on a PC with julia 32 bit on it...?

SimonDanisch commented 4 years ago

Well, you could serialize it with another format ;) Just duplicate this code here: https://github.com/JuliaPlots/AbstractPlotting.jl/blob/master/src/utilities/texture_atlas.jl#L102 With another format (e.g. JLD2?) You could also try to debug the problem... the code in texture_atlas isn't that big, so maybe easy? Also, I think you can download julia 32 bit binaries for 64 bit platforms, and that should/could also help to either reproduce, or serialize ;)

yakir12 commented 4 years ago

OK, tried all sorts of serialization methods but ran into various problems (BSON, JLD, JLD2, HDF5, etc). Tried to serialize from a local 32 bit Julia, ran into problems there too. So debugging: I'm not sure, but maybe this line is running into problems with Int32 wrapping around its max...?

yakir12 commented 4 years ago

By god I think I was right! After changing that line to

    _w, _h = size(img)
    @show _w, _h
    w = Float64(_w)
    h = Float64(_h)
    maxval = (w*h)^2
    @show maxval

the caching worked. maxval printed to as high as 5.187600625e9 which is higher than typemax(Int32) = 2147483647.

But now I I got: printing scene as text -> build GLMakie -> error of GLFW -> build GLFW (make sure I have libglfw3) -> build GLMakie again -> same error as before.

This is not headless right now, I have i3 working on this pi, so... But what should I try now?

SimonDanisch commented 4 years ago

You can try: https://github.com/JuliaGL/GLFW.jl/pull/191 As far as I can tell from https://github.com/JuliaBinaryWrappers/GLFW_jll.jl/releases, it should have the right binaries

yakir12 commented 4 years ago

Erg... Getting some GitError EAMBIGUOUS, asked about it on that PR (here).

yakir12 commented 4 years ago

Just to be clear, from my tests, the original issue is that line JuliaPlots/GLMakie.jl#34:

maxval = prod(size(img))^2

silently overflows on 32bit machines. No real idea for how to fix that other than converting it to a float, something like this:

maxval = prod(size(convert(Tuple{Float64, Float64}, size(img))))^2

If this looks good, I'll gladly PR, but I have to admit that I'm uncertain if this indeed is the best way to solve such problems.

SimonDanisch commented 4 years ago

Maybe maxval = prod(Int64.(size(img)))^2 ?

yakir12 commented 4 years ago

The Int64 fix "fixes" it but note that on the RPI:

julia> Int64(typemax(Int32) + 1)
-2147483648

(while on a 64bit machine that wouldn't overflow like that). and then I get these warnings when I tried your fix:

julia> using AbstractPlotting, GLMakie
[ Info: Precompiling AbstractPlotting [537997a7-5e4e-5d89-9595-2241ea00577e]
[ Info: Precompiling GLMakie [e9467ef8-e4e7-5192-8a1a-b1aee30e663a]

julia> image(rand(RGBf0, 10,10))
[ Info: Caching fonts, this may take a while. Needed only on first run!
┌ Warning: `a::StaticArray + b::Number` is deprecated, use `a .+ b` instead.
│   caller = (::AbstractPlotting.var"#49#50"{AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_Fac
└ @ AbstractPlotting ~/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:186
┌ Warning: `a::StaticArray - b::Number` is deprecated, use `a .- b` instead.
│   caller = (::AbstractPlotting.var"#49#50"{AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_Fac
└ @ AbstractPlotting ~/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:186
┌ Warning: `a::StaticArray + b::Number` is deprecated, use `a .+ b` instead.
│   caller = + at operators.jl:529 [inlined]
└ @ Core ./operators.jl:529
┌ Warning: `a::StaticArray + b::Number` is deprecated, use `a .+ b` instead.
│   caller = (::AbstractPlotting.var"#49#50"{AbstractPlotting.TextureAtlas,Char,Array{Ptr{FreeType.FT_Fac
└ @ AbstractPlotting ~/.julia/packages/AbstractPlotting/B5nOF/src/utilities/texture_atlas.jl:194

So doesn't seem to be ideal? But It works! So GLMakie can produce an image and all on the RPI!

SimonDanisch commented 4 years ago

Nice :) Yeah, those warnings are fixed on AbstractPlotting#master

yakir12 commented 4 years ago

I have to admit, I'm shocked that any number that could overflow in any code can render 32bit systems useless. I for onw have no idea if any of the code I write can guard against that. It might be good to test for that in a more rigorous way. Imagine a package that takes your code and looks for variables that could be higher than 90% of 2^31 - 1...

Anyways, still not sure about what to do about that maxval... How many more of these are there, lurking in the dark...

ffreyer commented 4 weeks ago

Closing this as stale and for being more of a Raspberry pi problem.