-
Notifications
You must be signed in to change notification settings - Fork 17
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
Launching window twice causes segfault #48
Comments
Expected behavior: throw an exception, not segfault. Extra credit: add an example in the documentation explaining how to do what I'm trying to do, but the correct way (or tell me personally and I'll update the docs). |
So, the issue is the application is returning from the #!/usr/bin/ruby
require 'glimmer-dsl-libui'
include Glimmer
def show_win
window('foo') {
button('Boom') {
on_clicked {
puts "boom"
}
}
}.show
end
show_win
show_win Returning from a method is not a proper way for exiting a GUI application. The proper way is for the user to click the x button in the window, or for the application to destroy the window and then quit #!/usr/bin/ruby
require 'glimmer-dsl-libui'
include Glimmer
def show_win
window('foo') { |w|
button('Boom') {
on_clicked {
puts "boom"
w.destroy
::LibUI.quit
}
}
}.show
end
show_win
show_win That should accomplish what you want as every time you click the This behavior is partially documented under: https://github.com/AndyObtiva/glimmer-dsl-libui#smart-defaults-and-conventions I just added extra documentation about it under Common Control Operations: ### Common Control Operations
- `destroy` (note that for closing a `window`, in addition to calling `somewindow.destroy`, you also have to call `::LibUI.quit`)
... If you feel there is a need to provide further clarification (like for a use-case I am not aware of), or even an example as you suggested, please feel free to ask or just share a Pull Request! Please confirm to me that the examples above resolve your issue in order for me to close this issue (or feel free to ask other questions if needed). |
Interesting! Apparently, if you really insist on the method return approach, this code makes it work (on the Mac at least, where I ran it): #!/usr/bin/ruby
require 'glimmer-dsl-libui'
include Glimmer
def show_win
window('foo') { |w|
button('Boom') {
on_clicked {
w.destroy
::LibUI.quit
return "boom"
}
}
}.show
return "done"
end
puts show_win
puts show_win I don't recommend it, but if you really want to return from the method (instead of calling a model method as per MVC), the code above works. I am of the belief that there are always exceptions to the rule, and it is good to bend rules to be pragmatic every once in a while (staying mindful of the pros/cons vs other approaches). So, perhaps in a quick and dirty Ruby scripting situation, this method return approach might be helpful. But, I'd still think twice before applying it. |
One more thing. When running the original application, I don't get a seg fault on the Mac. I get an
That is totally correct as it is mentioning that returning is unexpected behavior. If you are still encountering this somehow, it might be an issue on a specific environment. I know that Linux does not support launching a window multiple times within the same Ruby session unfortunately. It is a known problem observed when using Please confirm what environment you are on (Linux, Windows, or Mac) if the code snippets above do not resolve your issue. |
OK, I just tested your application in Linux and confirmed that in Linux, unlike on the Mac, I don't get an I am reporting this issue to the upstream projects (libui C library and bindings). I will report back here once it is fixed. |
Thanks so much for the information and for reporting the issue upstream! The problem I'm (clumsily) trying to solve is that I need a dialog box asking for input from the user. I need this at several points in the application, so I wrote a function that creates said dialog box. Once the user presses "OK" or "Cancel" I want the function to return the user input (or I actually tried something similar to your approach (calling |
You're welcome. I reported your issue at the underlying C libui project: And, the libui binding project: In the meantime, here is a workaround. You can write multiple Ruby applications that call each other conditionally based on your specific needs' logic. That way, instead of attempting to relaunch a window in the same Ruby application, you simply call another Ruby application to launch a window in a separate Ruby session (using I actually used this approach (using You can go ahead and verify that for yourself by launching it via these instructions ( I hope this will address your needs until the reported issue is fixed. Cheers! |
I have this same issue on Windows. Also issue 45 on windows. |
Probably I'm just doing something stupid and wrong, but the documentation didn't tell me how to do what I was trying to do (write a function that displays a window whenever its called). I figured I'd give it a go anyway, and it works brilliantly the first time it's called, but the second time the world falls apart.
Minimal reproduction:
I assume
return "boom"
is the problem here; probably the UI loop needs to clean something up. I tried callingwindow.destroy
beforereturn
, but that did not help.The text was updated successfully, but these errors were encountered: