Open SimonDanisch opened 6 years ago
In your callback you need to put @Gtk.sigatom
in front of any expression that changes something in Gtk.
Oh duh!
Warning: it is essential to avoid task switching inside Gtk callbacks, as this corrupts the Gtk C-stack. For example, use @async print or queue a message for yourself. You can also call GLib.g_yield() if you need to block. However, if you are still seeing segfaults in some random method due to there existing a callback that recursively calls the glib main loop (such as making a dialog box) or otherwise causes g_yield to be called, wrap the faulting code in GLib.@sigatom. This will postpone execution of that code block until it can be run on the proper stack (but will otherwise acts like normal control flow).
Could we fail more gracefully? Although I guess we can't, if that warning is already in the README
The situation is absolutely bad. I would love if someone could fix all this stuff.
(I am unfortunately not capable of fixing these things)
But the @sigatom
doesn't fix it, I think :( I'll try minimize the example, because right now, it's a bit too messy to really figure out what's going on! Well, at least I found out, that every ~3rd time the example code just works without a problem :D
Where did you put it? at least in front of the the push!
calls in the callbacks
Okay I reduced it to:
using Gtk, GLFW
using Gtk.GConstants
function setup_screen()
resolution = (600, 500)
name = "GTK + GLVisualize"
parent = Gtk.Window(name, resolution..., true, true)
Gtk.visible(parent, true)
Gtk.setproperty!(parent, Symbol("is-focus"), false)
box = Gtk.Box(:v)
push!(parent, box)
sl = Gtk.Scale(false, 0:10)
push!(box, sl)
gl_area = Gtk.GLArea()
Gtk.gl_area_set_required_version(gl_area, 3, 3)
push!(box, gl_area)
Gtk.setproperty!(box, :expand, gl_area, true)
Gtk.showall(parent)
return parent
end
initialized = GLFW.Init()
parent = setup_screen();
Gtk.showall(parent)
the GLFW.Init()
actually usually happens in GLFW.jl in __init__
, but I commented that out to reduce the issue... This segfaults reliably on my system - not on my windows machine though :D
Newest gdb stack trace:
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.6.1 (2017-10-24 22:15 UTC)
_/ |\__'_|_|_|\__'_| |
|__/ | x86_64-linux-gnu
julia> using Gtk, GLFW
[Thread 0x7fffb5ffb700 (LWP 18585) exited]
[Thread 0x7fffb87fc700 (LWP 18584) exited]
[Thread 0x7fffbaffd700 (LWP 18583) exited]
[Thread 0x7fffbd7fe700 (LWP 18582) exited]
[Thread 0x7fffbffff700 (LWP 18581) exited]
[Thread 0x7fffc8d50700 (LWP 18580) exited]
[Thread 0x7fffc9551700 (LWP 18579) exited]
[New Thread 0x7fffb5ffb700 (LWP 18588)]
[New Thread 0x7fffb87fc700 (LWP 18589)]
[New Thread 0x7fffbaffd700 (LWP 18590)]
julia> function setup_screen()
parent = Gtk.Window("GTK + GLVisualize", 600, 500, true, true)
Gtk.visible(parent, true)
box = Gtk.Box(:v)
push!(parent, box)
sl = Gtk.Scale(false, 0:10)
push!(box, sl)
gl_area = Gtk.GLArea()
Gtk.gl_area_set_required_version(gl_area, 3, 3)
push!(box, gl_area)
Gtk.showall(parent)
return parent
end
setup_screen (generic function with 1 method)
julia> initialized = GLFW.Init()
true
julia> parent = setup_screen();
julia>
Thread 1 "julia" received signal SIGSEGV, Segmentation fault.
__GI___pthread_mutex_lock (mutex=0x415353454d5f434c)
at ../nptl/pthread_mutex_lock.c:67
67 ../nptl/pthread_mutex_lock.c: No such file or directory.
(gdb) stacktrace
Undefined command: "stacktrace". Try "help".
(gdb) backtrace
#0 __GI___pthread_mutex_lock (mutex=0x415353454d5f434c)
at ../nptl/pthread_mutex_lock.c:67
#1 0x00007fffbfafebfa in XrmQGetResource ()
from /usr/lib/x86_64-linux-gnu/libX11.so.6
#2 0x00007fffbfadaf86 in XGetDefault ()
from /usr/lib/x86_64-linux-gnu/libX11.so.6
#3 0x00007fffaa86393f in ?? () from /usr/lib/x86_64-linux-gnu/libcairo.so.2
#4 0x00007fffaa865e60 in ?? () from /usr/lib/x86_64-linux-gnu/libcairo.so.2
#5 0x00007fffaa837627 in cairo_surface_get_font_options ()
from /usr/lib/x86_64-linux-gnu/libcairo.so.2
#6 0x00007fffaa7f5cff in ?? () from /usr/lib/x86_64-linux-gnu/libcairo.so.2
#7 0x00007fffaa7f8e13 in ?? () from /usr/lib/x86_64-linux-gnu/libcairo.so.2
#8 0x00007fffaa7eaa44 in cairo_show_glyphs ()
from /usr/lib/x86_64-linux-gnu/libcairo.so.2
#9 0x00007fffbfdfb22b in ?? ()
from /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0
#10 0x00007fffbfdfb5bf in ?? ()
from /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0
#11 0x00007fffa9a24c79 in pango_renderer_draw_glyphs ()
from /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
#12 0x00007fffa9a25930 in pango_renderer_draw_layout_line ()
from /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
#13 0x00007fffa9a25b45 in pango_renderer_draw_layout ()
---Type <return> to continue, or q <return> to quit---
from /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0
#14 0x00007fffbfdfb76a in ?? ()
from /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0
#15 0x00007fffc8eaa75e in gtk_render_layout ()
from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#16 0x00007fffc8eb493e in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#17 0x00007fffc8f80917 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#18 0x00007fffc8f80f23 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#19 0x00007fffc8d7825b in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#20 0x00007fffc8d7c962 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#21 0x00007fffc8d38492 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#22 0x00007fffc8f80917 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#23 0x00007fffc8f80f23 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#24 0x00007fffc8d7825b in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#25 0x00007fffc8d7c962 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#26 0x00007fffc8f8b839 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#27 0x00007fffc8f80917 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#28 0x00007fffc8f80d17 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#29 0x00007fffc8f80f02 in ?? () from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#30 0x00007fffc8f8114b in gtk_widget_send_expose ()
from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#31 0x00007fffc8e35052 in gtk_main_do_event ()
from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
#32 0x00007fffc8985d08 in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#33 0x00007fffc8986e2c in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#34 0x00007fffc8986fe3 in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#35 0x00007fffab7861d4 in ?? ()
from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so
#36 0x00007fffab7a09a6 in g_signal_emit_valist ()
from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so
#37 0x00007fffab7a1555 in g_signal_emit_by_name ()
from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so
#38 0x00007fffc897ffc7 in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#39 0x00007fffc896f3c8 in ?? () from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
#40 0x00007fffab4afab3 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#41 0x00007fffab4af04a in g_main_context_dispatch ()
from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#42 0x00007fffab4af3f0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#43 0x00007fffab4af712 in g_main_loop_run ()
from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#44 0x00007fffc8e34395 in gtk_main ()
from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#45 0x00007fffafee0b60 in julia_#229_68391 ()
at /home/s/.julia/v0.6/Gtk/src/events.jl:2
#46 0x00007fffafee0b80 in jlcall_#229_68390 ()
#47 0x00007ffff75e1250 in jl_call_fptr_internal (fptr=0x7fffffffcb30,
---Type <return> to continue, or q <return> to quit---
meth=0x7fffac6ef710, args=0x7fffffffcc80, nargs=1)
at /home/s/juliastuff/julia06dev/src/julia_internal.h:339
#48 0x00007ffff75e1361 in jl_call_method_internal (meth=0x7fffac6ef710,
args=0x7fffffffcc80, nargs=1)
at /home/s/juliastuff/julia06dev/src/julia_internal.h:358
#49 0x00007ffff75e7a32 in jl_apply_generic (args=0x7fffffffcc80, nargs=1)
at /home/s/juliastuff/julia06dev/src/gf.c:1926
#50 0x00007fffafee042f in julia_g_sigatom_68389 (f=0x7fffecd38408)
at /home/s/.julia/v0.6/Gtk/src/GLib/signals.jl:167
#51 0x00007fffafee0b43 in jlcall_g_sigatom_68388 ()
#52 0x00007ffff75e1250 in jl_call_fptr_internal (fptr=0x7fffffffce80,
meth=0x7fffac701090, args=0x7fffffffcf80, nargs=2)
at /home/s/juliastuff/julia06dev/src/julia_internal.h:339
#53 0x00007ffff75e1361 in jl_call_method_internal (meth=0x7fffac701090,
args=0x7fffffffcf80, nargs=2)
at /home/s/juliastuff/julia06dev/src/julia_internal.h:358
#54 0x00007ffff75e7a32 in jl_apply_generic (args=0x7fffffffcf80, nargs=2)
at /home/s/juliastuff/julia06dev/src/gf.c:1926
#55 0x00007ffff75e0c64 in jl_apply (args=0x7fffffffcf80, nargs=2)
at /home/s/juliastuff/julia06dev/src/julia.h:1424
#56 0x00007ffff75e14ff in jl_invoke (meth=0x7fffac701090, args=0x7fffffffcf80,
nargs=2) at /home/s/juliastuff/julia06dev/src/gf.c:51
#57 0x00007fffafee01fa in julia_gtk_main_68386 ()
---Type <return> to continue, or q <return> to quit---
at /home/s/.julia/v0.6/Gtk/src/events.jl:1
#58 0x00007fffafee0240 in jlcall_gtk_main_68385 ()
#59 0x00007ffff75e1250 in jl_call_fptr_internal (fptr=0x7fffffffd030,
meth=0x7fffac6eeb90, args=0x7fffacf16f90, nargs=1)
at /home/s/juliastuff/julia06dev/src/julia_internal.h:339
#60 0x00007ffff75e1361 in jl_call_method_internal (meth=0x7fffac6eeb90,
args=0x7fffacf16f90, nargs=1)
at /home/s/juliastuff/julia06dev/src/julia_internal.h:358
#61 0x00007ffff75e7a32 in jl_apply_generic (args=0x7fffacf16f90, nargs=1)
at /home/s/juliastuff/julia06dev/src/gf.c:1926
#62 0x00007ffff7606d5b in jl_apply (args=0x7fffacf16f90, nargs=1)
at /home/s/juliastuff/julia06dev/src/julia.h:1424
#63 0x00007ffff7607ade in start_task ()
at /home/s/juliastuff/julia06dev/src/task.c:267
#64 0x0000000000000000 in ?? ()
https://github.com/JuliaGraphics/Gtk.jl/blob/master/src/GLib/signals.jl#L167 Julia 0.6.1, linux, gdb stack trace:
I played around a bit with
g_sigatom
, which the stack trace points to, but didn't really figure out how it's supposed to work. What I did figure out was, thatret = f()
doesn't actually return, so I was thinking there might be a yield in there, but seems like the f that got called is just a plain ccall (ccall((:gtk_widget_show_all, libgtk), Void, (Ptr{GObject},), w)
, I think)... So I'm not really sure what's going on here...Full code (will try to make an mwe if I have time):