andlabs / ui

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

panic while add column into table #354

Open wonter opened 5 years ago

wonter commented 5 years ago

Hi,

I wrote a simple APP which has a table and a button, and after click the button, my APP can insert a new column into table.

But the fact is, when i click the button, the APP panicked.

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fff5cb99232]

runtime stack:

...

This code can recurrent the panic.

package main

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

type tableHandler struct {
    data []ui.TableInt
}

var th *tableHandler
var tm *ui.TableModel

func init() {
    th = new(tableHandler)
    tm = ui.NewTableModel(th)
}

func (th *tableHandler) ColumnTypes(m *ui.TableModel) []ui.TableValue {
    return []ui.TableValue{ui.TableInt(0)}
}

func (th *tableHandler) NumRows(m *ui.TableModel) int {
    return len(th.data)
}

func (th *tableHandler) CellValue(m *ui.TableModel, row, column int) ui.TableValue {
    return th.data[row]
}

func (th *tableHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
    th.data[row] = value.(ui.TableInt)
}

func setupUI() {
    window := ui.NewWindow("demo", 680, 240, false)
    window.OnClosing(func(*ui.Window) bool {
        ui.Quit()
        return true
    })
    ui.OnShouldQuit(func() bool {
        window.Destroy()
        return true
    })

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

    table := ui.NewTable(&ui.TableParams{
        Model: tm,
    })
    table.AppendTextColumn("ID", 0, ui.TableModelColumnNeverEditable, nil)
    vbox.Append(table, false)

    button := ui.NewButton("add")
    button.OnClicked(onClicked)
    vbox.Append(button, false)

    window.SetChild(vbox)
    window.Show()
}

func onClicked(*ui.Button) {
    th.data = append(th.data, ui.TableInt(1))
    tm.RowInserted(0)
}

func main() {
    ui.Main(setupUI)
}
andlabs commented 5 years ago

Can you print the full stack trace?

wonter commented 5 years ago

Can you print the full stack trace?

@andlabs

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fff5cb99232]

runtime stack:
runtime.throw(0x40cff9a, 0x2a)
    /usr/local/go/src/runtime/panic.go:617 +0x72
runtime.sigpanic()
    /usr/local/go/src/runtime/signal_unix.go:374 +0x4a9

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x40694f0, 0xc000045c70, 0xc000045c68)
    /usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000045c40 sp=0xc000045c08 pc=0x4004b3b
github.com/andlabs/ui._Cfunc_uiTableModelRowInserted(0x4501620, 0x0)
    _cgo_gotypes.go:3635 +0x41 fp=0xc000045c70 sp=0xc000045c40 pc=0x405e9c1
github.com/andlabs/ui.(*TableModel).RowInserted.func1(0xc000010068, 0x0)
    /Users/wangtai/go/src/github.com/andlabs/ui/tablemodel.go:208 +0x67 fp=0xc000045cb0 sp=0xc000045c70 pc=0x40638a7
github.com/andlabs/ui.(*TableModel).RowInserted(0xc000010068, 0x0)
    /Users/wangtai/go/src/github.com/andlabs/ui/tablemodel.go:208 +0x35 fp=0xc000045cd0 sp=0xc000045cb0 pc=0x40628a5
main.onClicked(0xc00007e240)
    /tmp/demo.go:65 +0x65 fp=0xc000045d28 sp=0xc000045cd0 pc=0x4066255
github.com/andlabs/ui.pkguiDoButtonOnClicked(0x46528a0, 0x0)
    /Users/wangtai/go/src/github.com/andlabs/ui/button.go:60 +0x7c fp=0xc000045d60 sp=0xc000045d28 pc=0x406102c
github.com/andlabs/ui._cgoexpwrap_ec78165a61e2_pkguiDoButtonOnClicked(0x46528a0, 0x0)
    _cgo_gotypes.go:3852 +0x35 fp=0xc000045d80 sp=0xc000045d60 pc=0x405f055
runtime.call32(0x0, 0x7ffeefbfe8d0, 0x7ffeefbfe968, 0x10)
    /usr/local/go/src/runtime/asm_amd64.s:519 +0x3b fp=0xc000045db0 sp=0xc000045d80 pc=0x404c01b
runtime.cgocallbackg1(0x0)
    /usr/local/go/src/runtime/cgocall.go:314 +0x177 fp=0xc000045e28 sp=0xc000045db0 pc=0x4004ea7
runtime.cgocallbackg(0x0)
    /usr/local/go/src/runtime/cgocall.go:191 +0xc5 fp=0xc000045e90 sp=0xc000045e28 pc=0x4004c95
runtime.cgocallback_gofunc(0x4004b5f, 0x4068ae0, 0xc000045f20, 0x497f2a0700000001)
    /usr/local/go/src/runtime/asm_amd64.s:773 +0x9b fp=0xc000045eb0 sp=0xc000045e90 pc=0x404d5eb
runtime.asmcgocall(0x4068ae0, 0xc000045f20)
    /usr/local/go/src/runtime/asm_amd64.s:620 +0x42 fp=0xc000045eb8 sp=0xc000045eb0 pc=0x404d482
runtime.cgocall(0x4068ae0, 0xc000045f20, 0xc0000880d8)
    /usr/local/go/src/runtime/cgocall.go:131 +0x7f fp=0xc000045ef0 sp=0xc000045eb8 pc=0x4004b5f
github.com/andlabs/ui._Cfunc_uiMain()
    _cgo_gotypes.go:2508 +0x41 fp=0xc000045f20 sp=0xc000045ef0 pc=0x405e2d1
github.com/andlabs/ui.Main(0x40d0c90, 0xc000032788, 0xc000074058)
    /Users/wangtai/go/src/github.com/andlabs/ui/main.go:41 +0xff fp=0xc000045f70 sp=0xc000045f20 pc=0x40618cf
main.main()
    /tmp/demo.go:69 +0x2d fp=0xc000045f98 sp=0xc000045f70 pc=0x40662fd
runtime.main()
    /usr/local/go/src/runtime/proc.go:200 +0x20c fp=0xc000045fe0 sp=0xc000045f98 pc=0x402911c
runtime.goexit()
    /usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000045fe8 sp=0xc000045fe0 pc=0x404dd11
exit status 2
CheatCoder commented 5 years ago

When i use @wonter example my Program does not crash but i get a GLib "critical message" and can't see the number in the Table - have seen the critical message before but there was no "blank" insert by my programs.

(tmp:32568): GLib-GObject-CRITICAL **: 11:05:31.654: g_value_get_string: assertion 'G_VALUE_HOLDS_STRING (value)' failed

(tmp:32568): GLib-GObject-CRITICAL **: 11:05:31.655: g_value_get_boxed: assertion 'G_VALUE_HOLDS_BOXED (value)' failed

(tmp:32568): GLib-GObject-CRITICAL **: 11:05:31.662: g_value_get_string: assertion 'G_VALUE_HOLDS_STRING (value)' failed

(tmp:32568): GLib-GObject-CRITICAL **: 11:05:31.662: g_value_get_boxed: assertion 'G_VALUE_HOLDS_BOXED (value)' failed

(tmp:32568): GLib-GObject-CRITICAL **: 11:05:31.662: g_value_get_string: assertion 'G_VALUE_HOLDS_STRING (value)' failed

(tmp:32568): GLib-GObject-CRITICAL **: 11:05:31.662: g_value_get_boxed: assertion 'G_VALUE_HOLDS_BOXED (value)' failed
baltuonis commented 4 years ago

Same problem, any updates?