Problem with setting an error handler
While I have been able to figure how to use quite a bit of the api, I am struggling with getting an error handler callback invoked.
package main
import (
"fmt"
"unsafe"
x11 "modernc.org/libX11"
"modernc.org/libc"
)
func main() {
tls := libc.NewTLS()
handler := func(tls *libc.TLS, display uintptr, bp uintptr) {
fmt.Println("error")
}
x11.XXSetErrorHandler(tls, uintptr(unsafe.Pointer(&handler)))
display := x11.XXOpenDisplay(tls, 0)
x11.XXMapWindow(tls, display, 17) // deliberate error, bad window id
var event x11.TXEvent
x11.XXNextEvent(tls, display, uintptr(unsafe.Pointer(&event)))
}
When the error handler function is called there's a segment violation.
unexpected fault address 0x5f5260
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0x5f5260 pc=0x5f5260]
goroutine 1 gp=0xc0000061c0 m=0 mp=0x7e12e0 [running]:
runtime.throw({0x5e7a7d?, 0x5281c0?})
/home/mike/.local/go/src/runtime/panic.go:1067 +0x48 fp=0xc000035c50 sp=0xc000035c20 pc=0x469008
runtime.sigpanic()
/home/mike/.local/go/src/runtime/signal_unix.go:931 +0x26c fp=0xc000035cb0 sp=0xc000035c50 pc=0x46a46c
modernc.org/libX11.X_XError(0xc0000cc000, 0x7f13f1102020, 0x7f13f06001a0)
/home/mike/projects/libx11/ccgo_linux_amd64.go:61623 +0x293 fp=0xc000035d30 sp=0xc000035cb0 pc=0x52afd3
modernc.org/libX11._handle_error(0xc0000cc000, 0x7f13f1102020, 0x7f13f06001a0, 0x0)
/home/mike/projects/libx11/ccgo_linux_amd64.go:56715 +0x9e fp=0xc000035d98 sp=0xc000035d30 pc=0x5255be
modernc.org/libX11._handle_response(0xc0000cc000, 0x7f13f1102020?, 0x7f13f06001a0, 0x0?)
/home/mike/projects/libx11/ccgo_linux_amd64.go:56936 +0x85 fp=0xc000035de0 sp=0xc000035d98 pc=0x525f05
modernc.org/libX11.X_XReadEvents(0xc0000cc000, 0x7f13f1102020)
/home/mike/projects/libx11/ccgo_linux_amd64.go:57054 +0x265 fp=0xc000035e20 sp=0xc000035de0 pc=0x526345
modernc.org/libX11.XXNextEvent(0xc0000cc000, 0x7f13f1102020, 0xc000035e68)
/home/mike/projects/libx11/ccgo_linux_amd64.go:37099 +0x6c fp=0xc000035e50 sp=0xc000035e20 pc=0x51bc6c
main.main()
/home/mike/projects/xgo/errorhandler/main.go:22 +0xad fp=0xc000035f50 sp=0xc000035e50 pc=0x5b738d
runtime.main()
/home/mike/.local/go/src/runtime/proc.go:272 +0x28b fp=0xc000035fe0 sp=0xc000035f50 pc=0x436dab
runtime.goexit({})
/home/mike/.local/go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000035fe8 sp=0xc000035fe0 pc=0x470261
I suspect that there's probably something wrong with the way that I'm providing the callback function to XXSetErrorHandler
. I've tried to follow the code in X_XError
, but I can't quite figure out what the problem is.
Edited by Mike Pilsbury