JuliaImages / ImageView.jl

Interactive display of images and movies
MIT License
135 stars 34 forks source link

Chrash when pointer moves over image #278

Closed fedeinthemix closed 1 year ago

fedeinthemix commented 1 year ago

When I try the example on the main page

using ImageView, Images

img = load("somepic.jpg")
imshow(img)

I initially see the image. However, when I move the mouse pointer over the window Julia crashes with the following output:

(julia:52759): Gdk-CRITICAL **: 11:42:16.437: ../gdk/wayland/gdkdisplay-wayland.c:1400: Unable to create Cairo image surface: invalid value (typically too big) for the size of the input (surface, pattern, etc.)

signal (11): Segmentation fault
in expression starting at none:0
_gdk_wayland_shm_surface_get_wl_buffer at /workspace/srcdir/gtk/build-gtk/../gdk/wayland/gdkdisplay-wayland.c:1410
gdk_wayland_window_ensure_cairo_surface at /workspace/srcdir/gtk/build-gtk/../gdk/wayland/gdkwindow-wayland.c:983
gdk_wayland_window_ref_cairo_surface at /workspace/srcdir/gtk/build-gtk/../gdk/wayland/gdkwindow-wayland.c:1003
gdk_window_ref_impl_surface at /workspace/srcdir/gtk/build-gtk/../gdk/gdkwindow.c:2838 [inlined]
gdk_window_create_similar_surface at /workspace/srcdir/gtk/build-gtk/../gdk/gdkwindow.c:10163
cairo_surface_for at /nix/store/cdwzagvmcfigcciygirqxqiqdmarjf4b-julia-bin-1.8.3-Gtk-1.3.0/share/julia/packages/Gtk/src/cairo.jl:94
init_cairo_context at /nix/store/cdwzagvmcfigcciygirqxqiqdmarjf4b-julia-bin-1.8.3-Gtk-1.3.0/share/julia/packages/Gtk/src/cairo.jl:37
notify_resize at /nix/store/cdwzagvmcfigcciygirqxqiqdmarjf4b-julia-bin-1.8.3-Gtk-1.3.0/share/julia/packages/Gtk/src/cairo.jl:59
unknown function (ip: 0x7fa9b41afe0b)
g_closure_invoke at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
signal_emit_unlocked_R at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit_valist at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
gtk_widget_size_allocate_with_baseline at /workspace/srcdir/gtk/build-gtk/../gtk/gtkwidget.c:6177
gtk_frame_allocate_border at /workspace/srcdir/gtk/build-gtk/../gtk/gtkframe.c:888
gtk_css_gadget_allocate at /workspace/srcdir/gtk/build-gtk/../gtk/gtkcssgadget.c:790
gtk_frame_allocate at /workspace/srcdir/gtk/build-gtk/../gtk/gtkframe.c:851
gtk_css_gadget_allocate at /workspace/srcdir/gtk/build-gtk/../gtk/gtkcssgadget.c:790
gtk_frame_size_allocate at /workspace/srcdir/gtk/build-gtk/../gtk/gtkframe.c:789
g_closure_invoke at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
signal_emit_unlocked_R at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit_valist at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
gtk_widget_size_allocate_with_baseline at /workspace/srcdir/gtk/build-gtk/../gtk/gtkwidget.c:6177
gtk_box_size_allocate_no_center at /workspace/srcdir/gtk/build-gtk/../gtk/gtkbox.c:817
gtk_box_allocate_contents at /workspace/srcdir/gtk/build-gtk/../gtk/gtkbox.c:1211
gtk_css_gadget_allocate at /workspace/srcdir/gtk/build-gtk/../gtk/gtkcssgadget.c:790
gtk_box_size_allocate at /workspace/srcdir/gtk/build-gtk/../gtk/gtkbox.c:1225
g_closure_invoke at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
signal_emit_unlocked_R at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit_valist at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
gtk_widget_size_allocate_with_baseline at /workspace/srcdir/gtk/build-gtk/../gtk/gtkwidget.c:6177
gtk_window_size_allocate at /workspace/srcdir/gtk/build-gtk/../gtk/gtkwindow.c:7922
g_closure_invoke at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
signal_emit_unlocked_R at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit_valist at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
gtk_widget_size_allocate_with_baseline at /workspace/srcdir/gtk/build-gtk/../gtk/gtkwidget.c:6177
gtk_window_move_resize at /workspace/srcdir/gtk/build-gtk/../gtk/gtkwindow.c:10017
_g_closure_invoke_va at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit_valist at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
gtk_container_idle_sizer at /workspace/srcdir/gtk/build-gtk/../gtk/gtkcontainer.c:2066
_g_closure_invoke_va at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit_valist at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
g_signal_emit at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libgobject-2.0.so.0 (unknown line)
gdk_frame_clock_paint_idle at /workspace/srcdir/gtk/build-gtk/../gdk/gdkframeclockidle.c:575
gdk_threads_dispatch at /workspace/srcdir/gtk/build-gtk/../gdk/gdk.c:769
g_timeout_dispatch at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libglib-2.0.so.0 (unknown line)
g_main_context_dispatch at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libglib-2.0.so.0 (unknown line)
g_main_context_iterate.isra.26 at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libglib-2.0.so.0 (unknown line)
g_main_loop_run at /nix/store/dfv5rz2a9pwyc2znr110nxwp2kw44c2k-julia-env/share/julia/artifacts/1cfe0ebb804cb8b0d7d1e8f98e5cda94b2b31b3d/lib/libglib-2.0.so.0 (unknown line)
gtk_main at /workspace/srcdir/gtk/build-gtk/../gtk/gtkmain.c:1329
#253 at /nix/store/cdwzagvmcfigcciygirqxqiqdmarjf4b-julia-bin-1.8.3-Gtk-1.3.0/share/julia/packages/Gtk/src/events.jl:2
unknown function (ip: 0x7fa9b41d4f0f)
_jl_invoke at /cache/build/default-amdci5-6/julialang/julia-release-1-dot-8/src/gf.c:2365 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-6/julialang/julia-release-1-dot-8/src/gf.c:2547
g_sigatom at /nix/store/cdwzagvmcfigcciygirqxqiqdmarjf4b-julia-bin-1.8.3-Gtk-1.3.0/share/julia/packages/Gtk/src/GLib/signals.jl:176
gtk_main at /nix/store/cdwzagvmcfigcciygirqxqiqdmarjf4b-julia-bin-1.8.3-Gtk-1.3.0/share/julia/packages/Gtk/src/events.jl:1
unknown function (ip: 0x7fa9b41d4ecf)
_jl_invoke at /cache/build/default-amdci5-6/julialang/julia-release-1-dot-8/src/gf.c:2365 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-6/julialang/julia-release-1-dot-8/src/gf.c:2547
jl_apply at /cache/build/default-amdci5-6/julialang/julia-release-1-dot-8/src/julia.h:1839 [inlined]
start_task at /cache/build/default-amdci5-6/julialang/julia-release-1-dot-8/src/task.c:931
Allocations: 59589187 (Pool: 59573075; Big: 16112); GC: 47
Segmentation fault (core dumped)

Using Linux NixOS 22.11 (x86_64) Gnome 43.2 on Wayland Julia 1.8.3 ImageView.jl 0.11.2 Images.jl 0.25.2 Gtk.jl 1.3.0

timholy commented 1 year ago

It does not happen for me. But can you try add ImageView@0.11.1 and see if that fixes it?

Just in case it's image-specific, can you direct me to an image that triggers the crash for you? I tried testimage("lighthouse") from TestImages.jl, and that does not crash (for me).

timholy commented 1 year ago

Oh, also try ImageView@0.11.3, I forgot that was the latest release. In general you should update your packages, an important Gtk.jl bug-fix happened just a couple of days ago.

fedeinthemix commented 1 year ago

I tried ImageView@0.11.3 and ImageView@0.11.1 with testimage("lighthouse") and I get the same segmentation fault error with both version.

timholy commented 1 year ago

This is going to be very hard for me to debug since I can't replicate it. It may be Wayland-specific? (See the top few lines of the stacktrace.)

@giordano, any ideas? We're not relying in any way on the system Gtk, right? But presumably the distinction between Wayland and my default Ubuntu system still matters?

giordano commented 1 year ago

We're not relying in any way on the system Gtk, right?

No, and judging by the stack trace this is all happening inside our artifacts.

timholy commented 1 year ago

Is there a reasonable plan forward? macOS also seems to have issues, see https://github.com/JuliaImages/ImageView.jl/actions/runs/3841921340/jobs/6542696058, and more expansively https://github.com/JuliaGizmos/GtkObservables.jl/actions/runs/3842033680/jobs/6542932322. Of course these two (unlike the OP here) only happen on nightly, which is concerning on its own. But I can't replicate either issue locally.

fedeinthemix commented 1 year ago

I've found the problem. For some reason the library doesn't find the fonts. If I start julia as follows it works

FONTCONFIG_FILE=/etc/fonts/fonts.conf julia

With it, when I right click on the figure I get the following messages, but it doesn't crash anymore

julia> Gdk-Message: 17:45:46.161: Window 0x3ac3600 is a temporary window without parent, application will not be able to position it on screen.
(julia:33997): Gdk-CRITICAL **: 17:45:46.267: gdk_wayland_window_handle_configure_popup: assertion 'impl->transient_for' failed

Not sure if this is expected or not, especially the second, critical one.

The question now is: why doesn't it find the fonts. One peculiarity of NixOS worth mentioning is that the artifacts are made available to the packages as read only. Could this be a problem?

During compilation I notice the message Fontconfig error: No writable cache directories. Is ImageView trying to install fonts? Where?

fedeinthemix commented 1 year ago

I think I understand now. Julia's Fontconfig_jll distributes a configuration file that points to directories not used on NixOS. This is fixed by the env. variable. Then ImageView tries to install a font cache in the user home directory which on NixOS (building packages in a sandbox) is not accessible during package compilation, but it's not a problem.

So,in the end it was a matter of understanding how to use the package on a peculiar system like NixOS. But it would be nice to avoid segmentation fault errors even when no fonts are found :-)

Regarding the messages in the previous comment: They disappear if I set GDK_BACKEND=x11 and appear with GDK_BACKEND=wayland (which is the default on my system). In spite of this the package seems to work correctly (very little testing). Is any problem expected on Wayland? Do you recommend to set it to X11?

timholy commented 1 year ago

So,in the end it was a matter of understanding how to use the package on a peculiar system like NixOS. But it would be nice to avoid segmentation fault errors even when no fonts are found :-)

I don't think Julia folks can do anything about this. You could consider contacting the Gtk developers.

Is any problem expected on Wayland? Do you recommend to set it to X11?

I have no experience, so I really have no idea.

Congrats and great work on identifying the source of the bug!

fedeinthemix commented 1 year ago

Thanks for the help!