Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wierd bug with a nested checkbox #32

Closed
yakir12 opened this issue May 12, 2017 · 11 comments
Closed

Wierd bug with a nested checkbox #32

yakir12 opened this issue May 12, 2017 · 11 comments

Comments

@yakir12
Copy link
Contributor

yakir12 commented May 12, 2017

Why does this (albeit contrived) example not work?

using GtkReactive, Gtk.ShortNames
w = Window("a")
a = button("a")
b = Box(:h)
push!(b, a)
foreach(a) do _
    cb = checkbox(rand(Bool))
    foreach(println, cb)
    push!(b, cb)
end
push!(w, b)
showall(w)

Running this builds the checkbox and prints the boolean, but then it dies (pressing on the button doesn't produce any additional checkboxes nor prints the booleans). Rerunning this within the same session halts the Julia session and I need to pkill julia or Ctrl-Z.
I'm on Version 0.6.0-dev.1393 (2016-12-09 01:03 UTC)

@timholy
Copy link
Member

timholy commented May 12, 2017

I think I've seen something similar with a much more complicated example (one so complicated I made almost no headway debugging it). In my case it seemed to fall into a cycle and kept trying to create new windows.

For reference (and because I'm in the middle of something else and don't have time to pursue it further), the following is a workaround:

using GtkReactive, Gtk.ShortNames
w = Window("a")
a = button("a")
b = Box(:h)
push!(b, a)

function create_checkbox()
    global cb
    global b
    cb = checkbox(rand(Bool))
    push!(b, cb)
end

updater = map(signal(a); init=nothing) do _
    @schedule println("clicked")
    @schedule create_checkbox()
    nothing
end
push!(w, b)
showall(w)

This adds a new checkbox each time you click the button. (You have to showall(w) to see it, if memory serves.)

It might be worth pinging @JobJob and @shashi about this, since this could be a Reactive issue.

@yakir12
Copy link
Contributor Author

yakir12 commented May 12, 2017

Thanks for the workaround! I'll try it within the framework this is intended for. It helped me with my specific case (with some modifications). But it would be good if this just worked.

@JobJob
Copy link
Member

JobJob commented May 13, 2017

The equivalent code in Interact is also broken:

using Interact
a = button("a")
foreach(signal(a)) do _
    cb = checkbox(rand(Bool))
    foreach(println, signal(cb))
    display(cb)
end
display(a)

that was an issue in Reactive. I've fixed that in Pkg.checkout("Reactive", "job/queue-restart-issues") but it didn't seem to fix the OP here, I'm not sure why. It does seem to be a bug in Reactive, because Base.n_avail(Reactive._messages) is the same as the number of times the "a" button is pressed - indicating that Reactive isn't processing the message queue (push!es to signals) correctly. Anyway, will have another look at it tomorrow.

@JobJob
Copy link
Member

JobJob commented May 13, 2017

Ok I've fixed the issue in the OP on that branch now, but I'm not 100% happy with the solution, will see if I can improve it tomorrow. Let me know how you go with it.

@JobJob
Copy link
Member

JobJob commented May 13, 2017

Oh note, I also needed to add another showall(w) after adding the checkbox

...
foreach(a) do _
    cb = checkbox(rand(Bool))
    foreach(println, cb)
    push!(b, cb)
    showall(w)
end
...

@yakir12
Copy link
Contributor Author

yakir12 commented May 14, 2017

@JobJob's solution fixed both the example above and my actual code (I had to Pkg.checkout("Reactive", "queue-restart-issues"), without the job/).
I'll leave the closing to you guys, since the fix resides in Reactive, and not in GtkReactive, and it hasn't been merged yet.

@JobJob
Copy link
Member

JobJob commented May 14, 2017

Thanks for the minimal reproduction @yakir12 - I'd been running into this issue the last few days, but wasn't sure exactly what was up - this helped a lot!

@yakir12
Copy link
Contributor Author

yakir12 commented May 14, 2017

Spoke too soon. I'll hopefully be back with an example.

@yakir12
Copy link
Contributor Author

yakir12 commented May 14, 2017

I wrote a simplified version of my code. But I can't reproduce the same faulty behavior I have in my real code in this simplified version. I'll try to strip off all the layers of complexity from my real code and see what causes the problem. I'll be back...

@JobJob
Copy link
Member

JobJob commented May 15, 2017

So I take it from #33 Reactive can breathe easy, this is resolved with the fix above?

@yakir12
Copy link
Contributor Author

yakir12 commented May 15, 2017

That is correct.

@yakir12 yakir12 closed this as completed May 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants