AndyObtiva / glimmer-dsl-libui

Glimmer DSL for LibUI - Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library - The Quickest Way From Zero To GUI - If You Liked Shoes, You'll Love Glimmer! - No need to pre-install any prerequisites. Just install the gem and have platform-independent GUI that just works on Mac, Windows, and Linux.
MIT License
458 stars 15 forks source link

GTK Error rendering table with zero initial elements #46

Closed rvs314 closed 1 year ago

rvs314 commented 1 year ago

When I run the following code:

require 'glimmer-dsl-libui'

Musician = Struct.new(:path, :instrument)

class Orchestra
  attr_accessor :musicians

  include Glimmer

  def initialize
    @musicians = []
  end

  def display
    window('Example') {
      vertical_box {
        button("Add New Musician") {
          stretchy false

          on_clicked do
            musicians << Musician.new("chair_#{@musicians.length}", "Air Guitar")
          end
        }
        table {
          text_column('Path')
          text_column('Instrument')

          cell_rows <= [self, :musicians]
        }
      }
    }.show
  end
end

w = Orchestra.new

# w.musicians << Musician.new("chair_0", "viola")

w.display

I get a window, but clicking the 'add musician' button doesn't do anything the first time. Clicking it again, a new musician is added. Clicking it a third time, the app crashes with the following error:

Gtk:ERROR:../../../gtk/gtkrbtree.c:471:_gtk_rbtree_insert_after: assertion failed: (_gtk_rbtree_is_nil (tree->root))
Bail out! Gtk:ERROR:../../../gtk/gtkrbtree.c:471:_gtk_rbtree_insert_after: assertion failed: (_gtk_rbtree_is_nil (tree->root))
aborted

Oddly enough, when you add back the commented line in the above code snippet, adding in an initial element before creating and showing the window object, everything works fine. Given the error message and behavior, I think it's safe to say that GTK is using a red-black tree which is entering an invalid state when initialized with zero elements. This makes sense, because from what I gleamed from the LibUI source, they use a GtkTreeModel for their table implementation. I don't know if the issue begins here or if it's somewhere upstream, but I'd be happy to move this somewhere if that's what's appropriate.

I'm using Debian GNU/Linux 6.1.0-6-amd64, ruby 3.1.2p20, XOrg Version: 1:7.7+23 and dwm-6.2.

AndyObtiva commented 1 year ago

Thank you for reporting. I was able to reproduce the issue. It is not a Linux GTK only issue, yet a general issue. It happens when doing explicit data-binding of table cell_rows to a model attribute that is an empty array. A similar issue (in table implicit data-binding) was recently reported here (already fixed): https://github.com/AndyObtiva/glimmer-dsl-libui/issues/36

In any case, I fixed your issue and released the fix in version 0.7.5: https://rubygems.org/gems/glimmer-dsl-libui/versions/0.7.5

Cheers.

AndyObtiva commented 1 year ago

Here is a screenshot demonstrating the fix by the way.

Screenshot from 2023-04-25 20-18-31