norisatir / go-gtk3

go-gtk3 - GTK3 BINDINGS FOR GO
BSD 3-Clause "New" or "Revised" License
58 stars 19 forks source link

go-gtk3 stopped working #2

Closed dersebi closed 12 years ago

dersebi commented 12 years ago

Something in my system must have been updated so that go-gtk3 does not work anymore. When starting the freshly compiled go-gtk3 demo on the current go weekly i get the following error:

$ ./demo 
panic: runtime error: assignment to entry in nil map

goroutine 1 [running]:
github.com/norisatir/go-gtk3/gobject.RegisterGoType(0x40, 0x42856b, 0x42ccea, 0x4f6e6a)
        go/src/pkg/github.com/norisatir/go-gtk3/gobject/_obj/closure.cgo1.go:722 +0x43
github.com/norisatir/go-gtk3/gobject.init·2()
        go/src/pkg/github.com/norisatir/go-gtk3/gobject/_obj/closure.cgo1.go:37 +0x2d
github.com/norisatir/go-gtk3/gobject.init()
        go/src/pkg/github.com/norisatir/go-gtk3/gobject/_obj/closure.cgo1.go:1164 +0x5e
github.com/norisatir/go-gtk3/pango.init()
        go/src/pkg/github.com/norisatir/go-gtk3/pango/_obj/pango.cgo1.go:3 +0x45
main.init()
       go/src/pkg/github.com/norisatir/go-gtk3/demo/demo.go:0 +0x3b

I was able to compile the same program on the 4th of January. I looked at my distributions update log (archlinux) but could not find an update to gtk3 or similar.

norisatir commented 12 years ago

I wasn't able to reproduce this problem in my archlinux boxes. I even freshly installed another one and demo still works. Did you compiled just demo app or entire go-gtk3? Try that first.

From the error above it seems that init() func from gtype.go didn't run before some other package wanted to register some type (presumably pango). I think this is Go related and has nothing to do with gobject/gtk3 libs on your system. I encountered this "nonsense" type of problems in the past when some package was compiled with different version of Go then program using it. But it's hard to tell just from above backtrace.

If you can get gdb backtrace, then please c/p that.

dersebi commented 12 years ago

I did a complete clean and rebuild of my entire go tree and all goinstalled packages now. Still the same problem. Do you have any advice how to get a gdb backtrace? As the program exits cleanly with error code 2 there is no running process to get a backtrace from. Even if I set a breakpoint on my main function the error happens before it is called.

This minimal example already produces the error:

package main

import (
    _ "github.com/norisatir/go-gtk3/gtk3"
)

func main() {
}
norisatir commented 12 years ago

when in gdb, type (gdb) b github.com/norisatir/go-gtk3/gobject.init This will set breakpoint on init func, before program crash.

Also, can you c/p that init func from file gobject/gtype.go (last one on bottom of the file).

When I remove this func then I get this exact error, which is expected.

norisatir commented 12 years ago

I just added additional error checking to repository. Try this updated version.

dersebi commented 12 years ago

With your new commit it works. I only have a panic when quitting my app that is probably caused by my code. Should I still try to step through gobject.init to find the original problem? I don't have the time right now, but could still do it tomorow.

dersebi commented 12 years ago

It's getting weirder and weirder. Your commit from yesterday did not fix the whole issue. I got more of the same errors when handling a focus-out-event signal. Also you demo application does not start, so I tried to debug it:

$ gdb ./demo
GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/me/go/src/pkg/github.com/norisatir/go-gtk3/demo/demo...done.
(gdb) b demo.go:129
Breakpoint 1 at 0x40180d: file /home/me/go/src/pkg/github.com/norisatir/go-gtk3/demo/demo.go, line 129.
(gdb) run
Starting program: /home/me/go/src/pkg/github.com/norisatir/go-gtk3/demo/demo 
[Thread debugging using libthread_db enabled]

Breakpoint 1, main.CreateTree (noname=void) at /home/me/go/src/pkg/github.com/norisatir/go-gtk3/demo/demo.go:129
129             selection.SetMode(gtk3.GtkSelectionMode.BROWSE)
(gdb) s
github.com/norisatir/go-gtk3/gtk3.(*TreeSelection).SetMode (self=0x0, gtk_SelectionMode=2)
    at /home/me/go/src/pkg/github.com/norisatir/go-gtk3/gtk3/gtk3.go:8645
8645            if model == nil {
(gdb) s
8646                    return nil
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x0000000000455b4a in github.com/norisatir/go-gtk3/gtk3.(*TreeSelection).SetMode (self=0x0, gtk_SelectionMode=2)
    at /home/me/go/src/pkg/github.com/norisatir/go-gtk3/gtk3/gtk3.go:8646
8646                    return nil
(gdb) 

Which is really weird, as line 8645 in gtk3.go is inside the (self CellView) SetModel() function and not inside (self TreeSelection)SetMode(). Maybe my distributions gcc update (4.6.2) broke something for the go compilers or cgo?

norisatir commented 12 years ago

As I suspected this is definitely Go related thing. SetMode method call shows that receiver is nil (self=0x0) which means that conversion from C object to Go structure doesn't happen. That in turn means that some, if not all, init() functions from packages don't execute. So, when in line 128 GetSelection method is executed it gets C object and tries to convert it to Go structure to return it to you. Conversion function for this C object should be registered in gtk3.go init function. Since this function didn't do it's job, converter doesn't know how to convert this type so it returns nil and than at breakpoint SetMode method is called on nil pointer and you get Segmentation fault. And this is your real problem here. Now, I too have gcc (4.6.2) in all my linux boxes and everything functions like it should.

As far as line numbers are concerned this is the issue with go/cgo and consequently gdb. They simply ignore cgo part of the file (which is huge in case of gtk3) and so they are wrongly reported. And that leads to huge frustrations and a cuple of broken keyboards :)

Now, I suggest you to open an issuse for Go in issues site. Or even ask on golang group if anyone has encountered similar problems. Or if you have public Dropbox account or anything similar, upload demo binary and send me a link and I'll compare it with mine.

dersebi commented 12 years ago

Here is an executable, that does not start on my system: https://www.dropbox.com/s/7qlylrb2zs6spt9/demo

I'll write a post to golang-nuts as soon as I get to it. For a real bug report I think the issue is not really all that clear to me. As there are currently some issues with the weekly go version I'll wait for a new release first. I also want to try on some other archs and linux distributions.

norisatir commented 12 years ago

Install go-gtk3 without goinstall. Clone repository and run gomake install && gomake demo. Then run demo. Let me know if that works.

dersebi commented 12 years ago

Good call. When I install go-gtk3 with goinstall I get the strange crashes, but when I install it manually everything seems to be working fine. I also tried the new "go install" command which shows the same behaviour as goinstall.

norisatir commented 12 years ago

Issue has been resolved in today's commit.