sqweek / dialog

Simple cross-platform dialog API for go-lang
ISC License
516 stars 78 forks source link

Unexpected error including `github.com/AllenDang/giu` #58

Closed cydside closed 3 years ago

cydside commented 3 years ago

Hi, I'm facing unexpected error including github.com/sqweek/dialog, clicking "Click Me" button, like in the following example:

Using alone both libraries working fine!

go get github.com/AllenDang/giu@latest
go get github.com/sqweek/dialog@latest
package main

import (
    "fmt"

    g "github.com/AllenDang/giu"
    "github.com/sqweek/dialog"
)

func onClickMe() {
    fmt.Println("Hello world!")
    file, err := dialog.File().Title("Save As").Filter("All Files", "*").Save()
    fmt.Println(file, err)
}

func onImSoCute() {
    fmt.Println("Im sooooooo cute!!")
}

func loop() {
    g.SingleWindow("hello world").Layout(
        g.Label("Hello world from giu"),
        g.Line(
            g.Button("Click Me").OnClick(onClickMe),
            g.Button("I'm so cute").OnClick(onImSoCute),
        ),
    )
}

func main() {
    wnd := g.NewMasterWindow("Hello world", 400, 200, g.MasterWindowFlagsNotResizable, nil)
    wnd.Run(loop)
}

Reporting error:

Hello world!
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x7f030d6fefc4]

runtime stack:
runtime.throw(0x8c1f53, 0x2a)
        /usr/local/go/src/runtime/panic.go:1117 +0x72
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:718 +0x2e5

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x601e30, 0xc00011b8a8, 0x0)
        /usr/local/go/src/runtime/cgocall.go:154 +0x5b fp=0xc00011b878 sp=0xc00011b840 pc=0x473e9b
github.com/sqweek/dialog._Cfunc_gtk_dialog_run(0x20162d0, 0x0)
        _cgo_gotypes.go:236 +0x45 fp=0xc00011b8a8 sp=0xc00011b878 pc=0x5ffdc5
github.com/sqweek/dialog.chooseFile.func11(0x20162d0, 0x21e7b30)
        /home/thenull/go/pkg/mod/github.com/sqweek/dialog@v0.0.0-20200911184034-8a3d98e8211d/dlgs_linux.go:93 +0x4d fp=0xc00011b8d8 sp=0xc00011b8a8 pc=0x6012ed
github.com/sqweek/dialog.chooseFile(0x8b26f7, 0x9, 0x8b147e, 0x4, 0x1, 0xc00011bc20, 0x0, 0x0, 0x0, 0x0)
        /home/thenull/go/pkg/mod/github.com/sqweek/dialog@v0.0.0-20200911184034-8a3d98e8211d/dlgs_linux.go:93 +0x390 fp=0xc00011bb18 sp=0xc00011b8d8 pc=0x600890
github.com/sqweek/dialog.(*FileBuilder).save(...)
        /home/thenull/go/pkg/mod/github.com/sqweek/dialog@v0.0.0-20200911184034-8a3d98e8211d/dlgs_linux.go:59
github.com/sqweek/dialog.(*FileBuilder).Save(0xc00011bc20, 0x0, 0x0, 0x0, 0x1)
        /home/thenull/go/pkg/mod/github.com/sqweek/dialog@v0.0.0-20200911184034-8a3d98e8211d/dlgs.go:121 +0x65 fp=0xc00011bb78 sp=0xc00011bb18 pc=0x5ffb05
main.onClickMe()
        /home/thenull/Sviluppo/dialogsqeak/dialog.go:31 +0x1cc fp=0xc00011bc68 sp=0xc00011bb78 pc=0x60188c
github.com/AllenDang/giu.(*ButtonWidget).Build(0xc00020a480)
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/Widgets.go:114 +0x74 fp=0xc00011bc98 sp=0xc00011bc68 pc=0x5fedd4
github.com/AllenDang/giu.(*LineWidget).Build(0xc000204dc8)
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/Widgets.go:49 +0xa8 fp=0xc00011bce0 sp=0xc00011bc98 pc=0x5fec68
github.com/AllenDang/giu.Layout.Build(0xc00011bd88, 0x2, 0x2)
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/Layout.go:12 +0x6b fp=0xc00011bd08 sp=0xc00011bce0 pc=0x5fd34b
github.com/AllenDang/giu.(*WindowWidget).Layout(0xc0002006f0, 0xc00011bd88, 0x2, 0x2)
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/Window.go:81 +0x109 fp=0xc00011bd40 sp=0xc00011bd08 pc=0x5ff449
main.loop()
        /home/thenull/Sviluppo/dialogsqeak/dialog.go:40 +0x225 fp=0xc00011bdb8 sp=0xc00011bd40 pc=0x601c85
github.com/AllenDang/giu.(*MasterWindow).render(0xc0000a0000)
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/MasterWindow.go:174 +0xa4 fp=0xc00011be28 sp=0xc00011bdb8 pc=0x5fe7a4
github.com/AllenDang/giu.(*MasterWindow).run.func1()
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/MasterWindow.go:192 +0x59 fp=0xc00011be68 sp=0xc00011be28 pc=0x5ff5f9
github.com/faiface/mainthread.Call.func1()
        /home/thenull/go/pkg/mod/github.com/faiface/mainthread@v0.0.0-20171120011319-8b78f0a41ae3/mainthread.go:63 +0x2f fp=0xc00011be98 sp=0xc00011be68 pc=0x566cef
github.com/faiface/mainthread.Run(0xc00009e4b0)
        /home/thenull/go/pkg/mod/github.com/faiface/mainthread@v0.0.0-20171120011319-8b78f0a41ae3/mainthread.go:44 +0xb1 fp=0xc00011bf20 sp=0xc00011be98 pc=0x566a71
github.com/AllenDang/giu.(*MasterWindow).Run(0xc0000a0000, 0x8c9d28)
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/MasterWindow.go:249 +0x65 fp=0xc00011bf40 sp=0xc00011bf20 pc=0x5fea45
main.main()
        /home/thenull/Sviluppo/dialogsqeak/dialog.go:51 +0x70 fp=0xc00011bf88 sp=0xc00011bf40 pc=0x601d70
runtime.main()
        /usr/local/go/src/runtime/proc.go:225 +0x256 fp=0xc00011bfe0 sp=0xc00011bf88 pc=0x4a8916
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc00011bfe8 sp=0xc00011bfe0 pc=0x4da3a1

goroutine 18 [chan receive]:
github.com/faiface/mainthread.Call(0xc0002006c0)
        /home/thenull/go/pkg/mod/github.com/faiface/mainthread@v0.0.0-20171120011319-8b78f0a41ae3/mainthread.go:66 +0xc5
github.com/AllenDang/giu.(*MasterWindow).run(0xc0000a0000)
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/MasterWindow.go:190 +0xa5
github.com/AllenDang/giu.(*MasterWindow).Run.func1()
        /home/thenull/go/pkg/mod/github.com/!allen!dang/giu@v0.5.3/MasterWindow.go:254 +0x4d
github.com/faiface/mainthread.Run.func1(0xc00009e4b0, 0xc0000a6000)
        /home/thenull/go/pkg/mod/github.com/faiface/mainthread@v0.0.0-20171120011319-8b78f0a41ae3/mainthread.go:37 +0x27
created by github.com/faiface/mainthread.Run
        /home/thenull/go/pkg/mod/github.com/faiface/mainthread@v0.0.0-20171120011319-8b78f0a41ae3/mainthread.go:36 +0xa5
exit status 2
MrCyjaneK commented 3 years ago

I'm getting the same error, hacky workaround for me was to ask for output path (use the dialog) before loading giu's GUI

gucio321 commented 3 years ago

I'm able to reproduce this behavior with a following code:

package main

import (
        "github.com/AllenDang/giu"
        "github.com/sqweek/dialog"
)

func loop() {
        isOpen := true
        giu.SingleWindow("Hello Warld").Pos(0, 0).IsOpen(&isOpen).Layout(giu.Layout{
                giu.Label("Some label"),
                giu.Button("click me").OnClick(func() {
                        _ = dialog.Message("clickMe clicked").YesNo()
                }),
        })
        giu.Update()
}

func main() {
        wnd := giu.NewMasterWindow("testwindow", 200, 200, 0, nil)
        wnd.Run(loop)
}

and I'm able to fix it modifing main function in a following way:

func main() {
        dialog.Message("some message").Error()
        wnd := giu.NewMasterWindow("testwindow", 200, 200, 0, nil)
        wnd.Run(loop)
}

so if we call dialog.Message on start, problem disappears.

cydside commented 3 years ago

Great! For the moment it fixes the program but hope for a package fix.

sqweek commented 3 years ago

Thanks. Same symptoms in this issue as the gtk3 crash in #51. Unfortunately I still lack convenient access to a system which can reproduce (there's no windows X server which supports GLX otherwise I could run glfw in WSL).

NetForces commented 3 years ago

Having the exact same issue on Ubuntu.

sqweek commented 3 years ago

@NetForces @cydside Can you see if this patch resolves the problem? (Remember to revert any other workarounds you have in place)

diff --git a/dlgs_linux.go b/dlgs_linux.go
index ee37221..dd53506 100644
--- a/dlgs_linux.go
+++ b/dlgs_linux.go
@@ -1,6 +1,8 @@
 package dialog

 // #cgo pkg-config: gtk+-3.0
+// #cgo LDFLAGS: -lX11
+// #include <X11/Xlib.h>
 // #include <gtk/gtk.h>
 // #include <stdlib.h>
 // static GtkWidget* msgdlg(GtkWindow *parent, GtkDialogFlags flags, GtkMessageType type,
@@ -13,6 +15,7 @@ import "C"
 import "unsafe"

 func init() {
+       C.XInitThreads()
        C.gtk_init(nil, nil)
 }
NetForces commented 3 years ago

@sqweek I will try to test this out today. Thanks

NetForces commented 3 years ago

@sqweek it works with the above modification (and that modification alone).

Can we expect a fix release soon ?

Thanks.

sqweek commented 3 years ago

@NetForces fixed in 9a201b5. Thanks for testing!