andlabs / ui

Platform-native GUI library for Go.
Other
8.33k stars 651 forks source link

GLib-CRITICAL **: g_ptr_array_add: assertion 'rarray' failed #346

Closed iqdecay closed 5 years ago

iqdecay commented 5 years ago

Hi, I did some research in the opened issues but nothing ressembled, sorry if it's a duplicate. Whenever I try to launch a program containing a tab layout, the programs just crashes. Weird thing is that the example "table.go" works (thanks to the workaround provided here). The full error message :

(process:7198): GLib-CRITICAL **: g_ptr_array_add: assertion 'rarray' failed

(process:7198): Gtk-CRITICAL **: gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed

(process:7198): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f0477099d99]

runtime stack:
runtime.throw(0x4fc0e0, 0x2a)
        /usr/local/go/src/runtime/panic.go:608 +0x72
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:374 +0x2f2

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4a7a50, 0xc00003a6e0, 0x4f6c7d)
        /usr/local/go/src/runtime/cgocall.go:128 +0x5e fp=0xc00003a6a8 sp=0xc00003a670 pc=0x41670e
github.com/andlabs/ui._Cfunc_uiNewWindow(0x18709a0, 0x3e8000003e8, 0x1, 0x0)
        _cgo_gotypes.go:3248 +0x4e fp=0xc00003a6e0 sp=0xc00003a6a8 pc=0x49cace
github.com/andlabs/ui.NewWindow(0x4f6c7d, 0xa, 0x3e8, 0x3e8, 0xc00001e101, 0x0)
        /home/lulwat/Development/go/src/github.com/andlabs/ui/window.go:28 +0x84 fp=0xc00003a728 sp=0xc00003a6e0 pc=0x4a1064
main.main()
        /home/lulwat/Development/go/src/timeTracker/tab.go:57 +0x51 fp=0xc00003a798 sp=0xc00003a728 pc=0x4a4771
runtime.main()
        /usr/local/go/src/runtime/proc.go:201 +0x207 fp=0xc00003a7e0 sp=0xc00003a798 pc=0x43ced7
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc00003a7e8 sp=0xc00003a7e0 pc=0x4650e1

One example that causes it (which I picked from this issue) :

package main

import (
    "fmt"
    "github.com/andlabs/ui"
)

type modelHandler struct {
    fileName string
    state string
    url string
    buttonText string
}

func newModelHandler() *modelHandler {
    m := new(modelHandler)
    m.fileName = "None"
    m.buttonText = "Small"
    return m
}

func (mh *modelHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
    return []ui.TableValue{
        ui.TableString(""), // column 0 text
        ui.TableString(""), // column 1 text
        ui.TableString(""), // column 2 text
        ui.TableString(""), // column 2 text
    }
}

func (mh *modelHandler) NumRows(m *ui.TableModel) int {
    return 6
}

func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
    switch column {
    case 0:
        return ui.TableString("")
    case 1:
        fallthrough
    case 2:
        return ui.TableString("")
    case 3:
        return ui.TableString("Normal")
    }
    panic("unreachable")
}

func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
    fmt.Println(row, column)
    if column == 3 {
        mh.fileName = "ABC"
    }
}

func SetupUI() {
    mainwin := ui.NewWindow("OSS Client", 1000, 1000, true)
    mainwin.OnClosing(func(*ui.Window) bool {
        ui.Quit()
        return true
    })
    ui.OnShouldQuit(func() bool {
        mainwin.Destroy()
        return true
    })

    vbox := ui.NewVerticalBox()
    vbox.SetPadded(true)

    hbox := ui.NewHorizontalBox()
    hbox.SetPadded(true)
    vbox.Append(hbox, false)
    hbox.Append(ui.NewButton("Add New Row Button"), false)

    mainwin.SetChild(vbox)

    mh := newModelHandler()
    model := ui.NewTableModel(mh)

    table := ui.NewTable(&ui.TableParams{
        Model: model,
        RowBackgroundColorModelColumn: -1,
    })
    vbox.Append(table, false)
    mainwin.SetChild(vbox)
    mainwin.SetMargined(true)

    table.AppendTextColumn("File name",
        0, ui.TableModelColumnNeverEditable, nil)

    table.AppendTextColumn("State", 1, ui.TableModelColumnNeverEditable, nil)
    table.AppendTextColumn("URL",
        2, ui.TableModelColumnNeverEditable, nil)

    table.AppendButtonColumn("Image size",
        3, ui.TableModelColumnAlwaysEditable)

    mainwin.Show()
}
func main() {
    SetupUI()
}

Is there something I'm doing wrong ? Or is it a bug ? Thank you for your time !

Here is the ouptut for dpkg -l libgtk2.0-0 libgtk-3-0 : -ii libgtk-3-0:amd64 3.18.9-1ubuntu3.3 amd64 GTK+ graphical user interface library -ii libgtk2.0-0:amd64 2.24.30-1ubuntu1.16. amd64 GTK+ graphical user interface library -rc libgtk2.0-0:i386 2.24.30-1ubuntu1.16. i386 GTK+ graphical user interface library

andlabs commented 5 years ago

That program has no tab layout. What's your main()?

iqdecay commented 5 years ago

Sorry, I added the main(). I don't use tab layouts in my other programs and it works fine, is a tab (like this ) necessary for using the table layout ? I can provide you with other examples of code that creates the same error.

andlabs commented 5 years ago

You need to call ui.Main in main. Pass it SetupUI.

iqdecay commented 5 years ago

It works, thank you !