-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
[Possible bug or strange behaviour] On 2nd run the libui window is black #45
Comments
Hi. @rubyFeedback Thank you for your Feedback. Sorry, I forgot about this problem for so long. When I first saw it, I thought it looked difficult and forgot about it. I am only connecting the C libui to the Ruby language interface and do not have a deep understanding of libui. I'm sure everyone has already noticed that I'm not that familiar with the C language. But even if I didn't know much about it, there are things I could figure out by looking at the code. My guess is that it is due to calling You say that's not true? Indeed Although libui looks like one library, it is actually a collection of three different libraries that behave in a similar way. For Unix, for macOS, and for Windows. Let's take a look at the Unix code. uiQuit is here. void uiQuit(void)
{
gdk_threads_add_idle(quit, NULL);
} Here the
Sorry if my explanation above is wrong. Read the libui code and find out for yourself. If you can read Ruby, you can read C. But in any case, if you're going to create a Window more than once, I'd suggest you delete the UI.quit on the last line. Best regards |
I am re-opening this issue because I encountered it too, but only on Linux. I reported it at the c libui project, but they were not able to reproduce it there, so it must be a Ruby libui binding issue: If I try to run this example (which simply duplicates the code of basic window twice), it runs on the Mac, but it fails to launch a window twice on Ubuntu Linux 22: require 'libui'
UI = LibUI
puts 'Run 1'
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
end
UI.main
UI.quit
puts 'Run 2'
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.control_destroy(main_window)
UI.quit
0
end
UI.main
UI.quit It was reported to me by 2 users:
This is an important feature to have to be able to conditionally open and close windows within the same application. It is useful for example in IRB or A fix would be highly appreciated. |
I am a bit confused about this issue. However, I still think that calling libui-ng/libui-ng#205 (comment) require "libui"
UI = LibUI
UI.init
# Create a new window
w = UI.new_window("hello world", 300, 30, 0)
UI.window_on_closing(w) { UI.quit; 1}
l = UI.new_label("Hello, World!")
UI.window_set_child(w, l)
UI.control_show(w)
UI.main
w = UI.new_window("hello world", 300, 30, 0)
UI.window_on_closing(w) { UI.quit; 1}
l = UI.new_label("Hello, World!")
UI.window_set_child(w, l)
UI.control_show(w)
UI.main
UI.uninit
So, the way I have been writing I started writing the LibUI samples based on the old Ruby binding using FFI created by jamescook, and you see the same usage here. This should also be written with reference to other libraries, and while it is one popular way of writing, I don't think it is the correct way. I think this is the biggest point of this issue, but there could be other problems as well... |
I am planning to make a change in all the examples of LibUI. |
Related to #45 Reported by @rubyFeedback and @AndyObtiva Thanks!!!
Hi, I experimented with using I encountered an issue when using a menu/quit-menu-item on the Mac. LibUI code (attempts to start an app 3 times): #!/usr/bin/ruby
require 'libui'
UI = LibUI
UI.init
menu = UI.new_menu('File')
UI.menu_append_quit_item(menu)
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.quit
1
end
UI.main
UI.uninit
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.quit
1
end
UI.main
UI.uninit
UI.init
main_window = UI.new_window('hello world', 300, 200, 1)
UI.control_show(main_window)
UI.window_on_closing(main_window) do
puts 'Bye Bye'
UI.quit
1
end
UI.main
UI.uninit If you do not think this is an issue in the LibUI Ruby binding, yet an issue with the libui-ng C library, please confirm to me and I will report the issue at libui-ng. |
Hi @AndyObtiva If menus do not work properly in previous versions, this may be related to the following problem. Once a Menu was set, flags such as git clone https://github.com/kojix2/LibUI
cd LibUI
rm -f vendor/libui.*
# Download latest libui-ng binary
bundle exec rake vendor:kojix2:auto
# Or you can compile from source code
bundle exec rake vendor:libui-ng:build
bundle exec ruby three_times_window.rb I will check the behavior on Mac tomorrow. |
Updated: |
Thank you for the update. I actually tested Linux from my side, and I didn't have the problem on Linux when using uninit. However, I do have the problem on MacOS as reported already. I look forward to you making a new release with the latest libui-ng binaries to resolve the issue on the Mac. |
Hey there kojix2,
I may have found a bug or at the least a weird behaviour.
First let me show the image - it shows a black window:
https://i.imgur.com/Sng4FNl.png
Next, here is how you can reproduce the behaviour:
First I took the code you showcase in the examples. I will copy/paste it next,
the only change I made was adding "class Button" so I can run this via
"Button.new":
Next, start irb. Do a:
or require_relative.
Then do:
This is now important! On the first run it works fine. No error.
But!
After you close the window, and do:
again, then this black window shows up. It looks to me as if it is
re-using some old data perhaps? Otherwise I would not know
why the second time it is run is different to the first run.
How did I discover this behaviour?
In one of my projects I use libui. I start it via a REPL, similar
to irb. First run is fine but second run always has this black
window. Perhaps I did something wrong, but the behaviour
by libui is quite strange - for instance, via ruby-gtk3 it works
just as expected, I always get the same widget when I run
it without any black window suddenly.
The text was updated successfully, but these errors were encountered: