# Julia Gtk segmentation violation when changing a GtkScale widget

**URL:** <https://discourse.julialang.org/t/julia-gtk-segmentation-violation-when-changing-a-gtkscale-widget/16877>\
**Category:** New to Julia\
**Created:** [October 27, 2018, 8:46pm UTC](https://discourse.julialang.org/t/julia-gtk-segmentation-violation-when-changing-a-gtkscale-widget/16877 "2018-10-27T20:46:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [October 28, 2018, 10:13am UTC](https://discourse.julialang.org/t/julia-gtk-segmentation-violation-when-changing-a-gtkscale-widget/16877/2 "2018-10-28T10:13:50Z")

</div>

This works for me, the main difference is that I pass `scale` as an argument instead of keeping it global (I recommend avoiding globals as much as possible). I also use the “full syntax” for `signal_connect`, which is a bit more complicated but more robust in my experience, see [this](https://github.com/JuliaGraphics/Gtk.jl/blob/master/doc/more_signals.md) for more details. The `@guarded` part is actually very useful, without it any errors in your callbacks will crash Gtk. Maybe there’s a way to do with the “simple” `signal_connect`, I’m not sure.

Read [this](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) also.

```julia
resetscale = true # set this false to avoid the crash
using Gtk
c = @GtkCanvas(200, 100)
win = GtkWindow("Crash demo")
g = GtkGrid()
push!(win, g)
scale = GtkScale(false, 0:50.)
cb = GtkComboBoxText()
push!(cb, "one")
push!(cb, "two")
set_gtk_property!(cb,:active,1)

function selectionchanged(index)
    println("selection changed to index $index")
end

@guarded (nothing) function cbchanged(widget, user_data)
    v = 30.
    scale = user_data
    idx = get_gtk_property(cb, :active, Int)
    str = Gtk.bytestring( GAccessor.active_text(cb) )
    selectionchanged(idx + 1) # change from zero- to 1-base
    if resetscale
        println("Prepare to set scale value to $v")
        Gtk.GAccessor.value(scale, v)
    end
    nothing
end

id = signal_connect(cbchanged, cb, "changed", Nothing, (), false, scale)

function scalechanged(widget)
    value = Gtk.GAccessor.value(widget)
    println("scale changed to $value")
    nothing
end
id = signal_connect(scalechanged, scale, "value_changed")
v = 45.

if resetscale   
    println("Prepare to set scale value to $v")
    Gtk.GAccessor.value(scale, v)
    println("Successfully set scale value to $v")
end
g[1:6,1] = c
g[2:5,2] = scale
g[1,2] = cb
showall(win)

```

---

_[View the full topic](https://discourse.julialang.org/t/julia-gtk-segmentation-violation-when-changing-a-gtkscale-widget/16877)._
