MakieOrg / Makie.jl

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

Including PyPlot and CairoMakie causes Segfaults, ReadOnlyMemoryErros and not drawn figures, depending on include order #3115

Open ThePurox opened 1 year ago

ThePurox commented 1 year ago

Including PyPlot before CairoMakie

When including the libraries in this order the more severe errors happen.

Plotting with CairoMakie, but not showing the plot causes a segfault when saving

>>> ] activate --temp; add CairoMakie; add PyPlot
>>> using PyPlot
>>> using CairoMakie

>>> x = 0:0.1:10
>>> fig, ax, l = lines(x, sin.(x)); # <- do not show plot
>>> save("testfig.pdf", fig)

[30910] signal (11.1): Segmentation fault
Details, click to show

``` in expression starting at REPL[6]:1 cairo_surface_get_font_options at /workspace/srcdir/cairo-1.16.0/src/cairo-surface.c:1603 cairo_surface_get_font_options at /usr/lib/libcairo.so.2 (unknown line) _pango_cairo_update_context at /workspace/srcdir/pango-1.50.9/build/../pango/pangocairo-context.c:111 pango_cairo_create_context at /workspace/srcdir/pango-1.50.9/build/../pango/pangocairo-context.c:453 pango_cairo_create_layout at /workspace/srcdir/pango-1.50.9/build/../pango/pangocairo-context.c:487 CairoContext at /home/nico/.julia/packages/Cairo/smWIA/src/Cairo.jl:558 [inlined] Screen at /home/nico/.julia/packages/CairoMakie/Ry75I/src/screen.jl:281 Screen at /home/nico/.julia/packages/CairoMakie/Ry75I/src/screen.jl:266 unknown function (ip: 0x7f6fe23a1222) unknown function (ip: 0x7f6ff2058420) #getscreen#1103 at /home/nico/.julia/packages/Makie/uAmck/src/display.jl:408 getscreen at /home/nico/.julia/packages/Makie/uAmck/src/display.jl:391 [inlined] #1099 at /home/nico/.julia/packages/Makie/uAmck/src/display.jl:324 #open#409 at ./io.jl:395 open at ./io.jl:392 [inlined] #save#1098 at /home/nico/.julia/packages/Makie/uAmck/src/display.jl:319 save at /home/nico/.julia/packages/Makie/uAmck/src/display.jl:297 unknown function (ip: 0x7f6fe239f10a) #save#1097 at /home/nico/.julia/packages/Makie/uAmck/src/display.jl:294 save at /home/nico/.julia/packages/Makie/uAmck/src/display.jl:291 unknown function (ip: 0x7f6fe239e07a) unknown function (ip: 0x7f6ff206495c) unknown function (ip: 0x7f6ff206413a) unknown function (ip: 0x7f6ff206525b) unknown function (ip: 0x7f6ff206613e) unknown function (ip: 0x7f6ff2082502) unknown function (ip: 0x7f6ff2082f19) ijl_toplevel_eval_in at /usr/bin/../lib/julia/libjulia-internal.so.1 (unknown line) unknown function (ip: 0x7f6fd8bb106c) unknown function (ip: 0x7f6fd8bb20a5) unknown function (ip: 0x7f6fd8bb2de6) unknown function (ip: 0x7f6fd8bb43db) unknown function (ip: 0x7f6fd8cb915b) unknown function (ip: 0x7f6fd8cbed83) unknown function (ip: 0x7f6fd8cbedbf) unknown function (ip: 0x7f6fd8befe5a) unknown function (ip: 0x7f6fd8befeab) jl_f__call_latest at /usr/bin/../lib/julia/libjulia-internal.so.1 (unknown line) unknown function (ip: 0x7f6fd9251582) unknown function (ip: 0x7f6fd9259185) unknown function (ip: 0x7f6fd925958f) unknown function (ip: 0x7f6fd9259698) unknown function (ip: 0x7f6ff20b0cf0) jl_repl_entrypoint at /usr/bin/../lib/julia/libjulia-internal.so.1 (unknown line) main at julia (unknown line) unknown function (ip: 0x7f6ff2a4584f) __libc_start_main at /usr/bin/../lib/libc.so.6 (unknown line) _start at julia (unknown line) Allocations: 31939197 (Pool: 31917041; Big: 22156); GC: 39 zsh: segmentation fault (core dumped) julia ```

When trying to show the plot a ReadOnlyMemoryError is thrown

>>> ] activate --temp; add CairoMakie; add PyPlot
>>> using PyPlot
>>> using CairoMakie

>>> x = 0:0.1:10
>>> fig, ax, l = lines(x, sin.(x)) # <- do show plot
Error showing value of type Makie.FigureAxisPlot:
ERROR: ReadOnlyMemoryError()
Stacktrace, click to show

``` Stacktrace: [1] CairoContext @ ~/.julia/packages/Cairo/smWIA/src/Cairo.jl:558 [inlined] [2] CairoMakie.Screen(scene::Scene, config::CairoMakie.ScreenConfig, surface::Cairo.CairoSurfaceImage{ColorTypes.ARGB32}) @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/screen.jl:281 [3] Screen @ ~/.julia/packages/CairoMakie/Ry75I/src/screen.jl:266 [inlined] [4] CairoMakie.Screen(scene::Scene, config::CairoMakie.ScreenConfig) @ CairoMakie ~/.julia/packages/CairoMakie/Ry75I/src/screen.jl:252 [5] getscreen(::Module, ::Scene; screen_config::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:408 [6] getscreen @ ~/.julia/packages/Makie/uAmck/src/display.jl:391 [inlined] [7] display(figlike::Makie.FigureAxisPlot; backend::Module, inline::MakieCore.Automatic, update::Bool, screen_config::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:161 [8] display(figlike::Makie.FigureAxisPlot) @ Makie ~/.julia/packages/Makie/uAmck/src/display.jl:131 [9] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any) @ REPL /usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:287 [10] with_repl_linfo(f::Any, repl::REPL.LineEditREPL) @ REPL /usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:557 ```

Including CairoMakie before PyPlot

When including the libraries in this order there are no segfaults and the correct pdfs are saved, however the matplotlib figure preview is not rendered.

>>> ] activate --temp; add CairoMakie; add PyPlot
>>> using CairoMakie
>>> using PyPlot

>>> x = 0:0.1:10
>>> fig, ax, l = lines(x, sin.(x)) # adding a ; here does not change the behavior
>>> save("testfig.pdf", fig)
>>> plt.plot(x, sin.(x)) # <- window opens, but no content is rendered
>>> plt.savefig("testfig-py.pdf")

System and Environment information

I'm on julia version 1.9.2 with the following library versions:

>>> ] status
Status `/tmp/jl_0gTl5D/Project.toml`
  [13f3f980] CairoMakie v0.10.7
  [d330b81b] PyPlot v2.11.1

Running on Manjaro Linux:

>>> uname -a
Linux btptx1 6.1.41-1-MANJARO #1 SMP PREEMPT_DYNAMIC Tue Jul 25 09:17:30 UTC 2023 x86_64 GNU/Linux

On dual Intel(R) Xeon(R) CPU E5-2640 v3, with a NVIDIA Quadro K2200.

jkrumbiegel commented 1 year ago

interesting, I would assume this is because both open the freetype library? This is the most stateful C thing we have in CairoMakie, Cairo itself is rather constrained to the surface you're currently working with I think.

jkrumbiegel commented 1 year ago

ah yeah top of the stacktrace is cairo_surface_get_font_options, that would fit