Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when WriteContext is called #92

Closed
txbrown opened this issue Jan 10, 2021 · 10 comments
Closed

Error when WriteContext is called #92

txbrown opened this issue Jan 10, 2021 · 10 comments

Comments

@txbrown
Copy link

txbrown commented Jan 10, 2021

Hi,

I was using gousb successfully until today. I honestly don't know what happened but now every time I try to run the same code that calls outEp.WriteContext(ctx, buffer) I get

Assertion failed: (pthread_mutex_lock(mutex) == 0), function usbi_mutex_lock, file ./os/threads_posix.h, line 46.
SIGABRT: abort
PC=0x7fff20353452 m=11 sigcode=0

I have code that hasn't been touched in weeks that is now failing but I don't know the reason. I may have upgraded libusb.

@zagrodzki
Copy link
Collaborator

What platform is this on? Can you downgrade libusb to the previous version and compare? The actual version numbers would be useful. Also a small code that reproduces the issue would be helpful.

@txbrown
Copy link
Author

txbrown commented Jan 11, 2021

@zagrodzki
platform: macos 11.1 Beta
libusb: 1.0.24 - believe this is the only one available now on homebrew - I had to reinstall my OS

some code

at this point I already opened the device session and have a handler to it and to the interface.

var abletonVendorID gousb.ID = 0x2982
var pushProductID gousb.ID = 0x1967
var frameHeader = []byte{0xff, 0xcc, 0xaa, 0x88,
	0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00}

var (
	debug = flag.Int("debug", 0, "libusb debug level (0..3)")
)

type AbletonPush2DisplayInterface interface {
	Open() error
	Close() error
}

// Display - Ableton Push 2 Display Interface
type AbletonPush2Display struct {
	pixels []byte
	device *gousb.Device
	ctx    *gousb.Context
	intf   *gousb.Interface
}

func (display *AbletonPush2Display) WritePixels(pixels []uint8) error {
	outEp, _ := display.intf.OutEndpoint(1)
	ctx := context.Background()

	_, err := outEp.WriteContext(ctx, frameHeader)
	_, err := outEp.WriteContext(ctx, pixels)

	return err
}

@txbrown
Copy link
Author

txbrown commented Jan 11, 2021

@zagrodzki unrelated to this project but the error output is pretty similar to what I have here
moby/moby#37916

@txbrown
Copy link
Author

txbrown commented Jan 12, 2021

@zagrodzki I was able to validate that the issue is due to libusb-1.0.24 being installed on my machine.
homebrew is defaulting to that and installing a specific version is really not straightforward.
Could I request support for libusb-1.0.24?

@zagrodzki
Copy link
Collaborator

I'm not sure yet what changes in 1.0.24 triggered this. In the meantime, please fix your code to not ignore the error from the OutEndpoint() as well as from the first WriteContext(). I'd like to see also the rest of the initialization code, i.e. how you obtain the USB context, open the config and claim the interface.

@zagrodzki
Copy link
Collaborator

Also please attach the full output, there's more data in there.

@txbrown
Copy link
Author

txbrown commented Jan 12, 2021

@zagrodzki thanks for the feedback. I pretty much went by an example I saw somewhere here on the repo to open device and claim the interface - it's been a while...

But please have a look as I am sure I am doing something really dumb. To be honest when doing this in c++ or wrapping libusb to use in swift I was successful as the api was pretty much what's on libusb docs. On this package some things feel slightly different and maybe this is because I haven't read enough of the docs - which I am currently going through again slowly.

Here is the repo with the code - although without the hardware it would fail running:

https://github.com/txbrown/fyne-push2-example

@txbrown
Copy link
Author

txbrown commented Jan 13, 2021

Here is the full console output as well

2021/01/13 10:17:21 Device opened
000.001 2982:1967 Unknown 2982:1967
  Protocol: (Defined at Interface level)
Assertion failed: (pthread_mutex_lock(mutex) == 0), function usbi_mutex_lock, file ./os/threads_posix.h, line 46.
SIGABRT: abort
PC=0x7fff202fa462 m=15 sigcode=0

goroutine 0 [idle]:
runtime: unknown pc 0x7fff202fa462
stack: frame={sp:0x70000eb39dc8, fp:0x0} stack=[0x70000eaba350,0x70000eb39f50)
000070000eb39cc8:  0000000000000000  0000000000000064 
000070000eb39cd8:  000000003d2ee000  000070000eb39d50 
000070000eb39ce8:  00007fff2036d575  0000000000000000 
000070000eb39cf8:  000070000eb39d20  0000000004aba766 
000070000eb39d08:  00007fff20280c6f  0000000000000000 
000070000eb39d18:  000070000eb39d68  000070000eb39d60 
000070000eb39d28:  0000000004aba7a6  0000000004aba7b6 
000070000eb39d38:  000000003d2ee000  000000000000002e 
000070000eb39d48:  0000000004aba766  000070000eb39e30 
000070000eb39d58:  00007fff2036b6a7  0000003000000030 
000070000eb39d68:  000070000eb39e40  000070000eb39d80 
000070000eb39d78:  0000000000000000  0000000004ad9a00 
000070000eb39d88:  0000000004adfe00  00007fff889882c0 
000070000eb39d98:  00007fff889aa4e0  00007fff2023470c 
000070000eb39da8:  0000000000000000  000070000eb39df0 
000070000eb39db8:  00007fff20237133  0000000000000000 
000070000eb39dc8: <00007fff20328610  0000000000000003 
000070000eb39dd8:  000000003d2ee028  000070000eb39e10 
000070000eb39de8:  0000000004aba766  000070000eb39e30 
000070000eb39df8:  00007fff2027b720  0000000004aba7a6 
000070000eb39e08:  000000000000002e  00007000fffff9df 
000070000eb39e18:  ffffffff2036b5e4  0000000004aba7a6 
000070000eb39e28:  000000000000002e  000070000eb39e70 
000070000eb39e38:  00007fff2027a9d6  0000000000000016 
000070000eb39e48:  000000c00005dd38  000000000cb0bdd0 
000070000eb39e58:  0000000000000000  000000000c120418 
000070000eb39e68:  0000000000000000  000070000eb39e80 
000070000eb39e78:  0000000004ab918c  000070000eb39ec0 
000070000eb39e88:  0000000004ab2665  00000000042db9d0 
000070000eb39e98:  000000c00005dd38  00000000000000fa 
000070000eb39ea8:  0000000000000000  000000c00005e000 
000070000eb39eb8:  0000000000000000  000070000eb39ef0 
runtime: unknown pc 0x7fff202fa462
stack: frame={sp:0x70000eb39dc8, fp:0x0} stack=[0x70000eaba350,0x70000eb39f50)
000070000eb39cc8:  0000000000000000  0000000000000064 
000070000eb39cd8:  000000003d2ee000  000070000eb39d50 
000070000eb39ce8:  00007fff2036d575  0000000000000000 
000070000eb39cf8:  000070000eb39d20  0000000004aba766 
000070000eb39d08:  00007fff20280c6f  0000000000000000 
000070000eb39d18:  000070000eb39d68  000070000eb39d60 
000070000eb39d28:  0000000004aba7a6  0000000004aba7b6 
000070000eb39d38:  000000003d2ee000  000000000000002e 
000070000eb39d48:  0000000004aba766  000070000eb39e30 
000070000eb39d58:  00007fff2036b6a7  0000003000000030 
000070000eb39d68:  000070000eb39e40  000070000eb39d80 
000070000eb39d78:  0000000000000000  0000000004ad9a00 
000070000eb39d88:  0000000004adfe00  00007fff889882c0 
000070000eb39d98:  00007fff889aa4e0  00007fff2023470c 
000070000eb39da8:  0000000000000000  000070000eb39df0 
000070000eb39db8:  00007fff20237133  0000000000000000 
000070000eb39dc8: <00007fff20328610  0000000000000003 
000070000eb39dd8:  000000003d2ee028  000070000eb39e10 
000070000eb39de8:  0000000004aba766  000070000eb39e30 
000070000eb39df8:  00007fff2027b720  0000000004aba7a6 
000070000eb39e08:  000000000000002e  00007000fffff9df 
000070000eb39e18:  ffffffff2036b5e4  0000000004aba7a6 
000070000eb39e28:  000000000000002e  000070000eb39e70 
000070000eb39e38:  00007fff2027a9d6  0000000000000016 
000070000eb39e48:  000000c00005dd38  000000000cb0bdd0 
000070000eb39e58:  0000000000000000  000000000c120418 
000070000eb39e68:  0000000000000000  000070000eb39e80 
000070000eb39e78:  0000000004ab918c  000070000eb39ec0 
000070000eb39e88:  0000000004ab2665  00000000042db9d0 
000070000eb39e98:  000000c00005dd38  00000000000000fa 
000070000eb39ea8:  0000000000000000  000000c00005e000 
000070000eb39eb8:  0000000000000000  000070000eb39ef0 

goroutine 67 [syscall]:
runtime.cgocall(0x42dc150, 0xc00005dd38, 0x43581e0)
        /usr/local/opt/go/libexec/src/runtime/cgocall.go:133 +0x5b fp=0xc00005dd08 sp=0xc00005dcd0 pc=0x400601b
github.com/google/gousb._Cfunc_submit(0xc120418, 0x0)
        _cgo_gotypes.go:676 +0x49 fp=0xc00005dd38 sp=0xc00005dd08 pc=0x40ee929
github.com/google/gousb.libusbImpl.submit.func1(0xc120418, 0x0)
        /Users/ricardoabreu/go/pkg/mod/github.com/google/[email protected]/libusb.go:455 +0x4d fp=0xc00005dd68 sp=0xc00005dd38 pc=0x40f254d
github.com/google/gousb.libusbImpl.submit(0xc120418, 0x10, 0xc120418)
        /Users/ricardoabreu/go/pkg/mod/github.com/google/[email protected]/libusb.go:455 +0x2b fp=0xc00005dd88 sp=0xc00005dd68 pc=0x40f118b
github.com/google/gousb.(*libusbImpl).submit(0x4988248, 0xc120418, 0xc000680480, 0xc00005ddf8)
        <autogenerated>:1 +0x3c fp=0xc00005ddb0 sp=0xc00005dd88 pc=0x40f7c7c
github.com/google/gousb.(*usbTransfer).submit(0xc000072680, 0x0, 0x0)
        /Users/ricardoabreu/go/pkg/mod/github.com/google/[email protected]/transfer.go:51 +0x93 fp=0xc00005ddf8 sp=0xc00005ddb0 pc=0x40ec0f3
github.com/google/gousb.(*endpoint).transfer(0xc0000d4070, 0x4495820, 0xc00001a090, 0x465bab0, 0x10, 0x10, 0x0, 0x0, 0x0)
        /Users/ricardoabreu/go/pkg/mod/github.com/google/[email protected]/endpoint.go:98 +0xc6 fp=0xc00005de78 sp=0xc00005ddf8 pc=0x40eae26
github.com/google/gousb.(*OutEndpoint).Write(...)
        /Users/ricardoabreu/go/pkg/mod/github.com/google/[email protected]/endpoint.go:160
fyne-app/display.(*AbletonPush2Display).WritePixels(0xc0004779e0, 0xc000c7e000, 0x50000, 0x50000, 0x50000, 0xc00005df30)
        /Users/ricardoabreu/fyne-app/display/display.go:114 +0xa5 fp=0xc00005ded8 sp=0xc00005de78 pc=0x41ad5a5
main.runFyneApp.func1()
        /Users/ricardoabreu/fyne-app/main.go:47 +0xf4 fp=0xc00005df40 sp=0xc00005ded8 pc=0x42db594
fyne.io/fyne/widget.(*Button).Tapped(0xc0001304d0, 0xc000486ee0)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/widget/button.go:196 +0xa7 fp=0xc00005df78 sp=0xc00005df40 pc=0x428f9e7
fyne.io/fyne/internal/driver/glfw.(*window).mouseClicked.func5()
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/window.go:738 +0x38 fp=0xc00005df98 sp=0xc00005df78 pc=0x42b8658
fyne.io/fyne/internal/driver/glfw.(*window).runEventQueue(0xc00091a1a0)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/window.go:1156 +0x7a fp=0xc00005dfd8 sp=0xc00005df98 pc=0x42b59ba
runtime.goexit()
        /usr/local/opt/go/libexec/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00005dfe0 sp=0xc00005dfd8 pc=0x406b901
created by fyne.io/fyne/internal/driver/glfw.(*gLDriver).createWindow.func1
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/window.go:1180 +0x10d

goroutine 1 [select, locked to thread]:
fyne.io/fyne/internal/driver/glfw.(*gLDriver).runGL(0xc00007c140)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/loop.go:90 +0x1bf
fyne.io/fyne/internal/driver/glfw.(*gLDriver).Run(0xc00007c140)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/driver.go:74 +0x3a
fyne.io/fyne/internal/driver/glfw.(*window).ShowAndRun(0xc00091a1a0)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/window.go:440 +0x57
main.runFyneApp()
        /Users/ricardoabreu/fyne-app/main.go:56 +0x325
main.main()
        /Users/ricardoabreu/fyne-app/main.go:13 +0x25

goroutine 50 [sleep]:
time.Sleep(0x22ecb25c00)
        /usr/local/opt/go/libexec/src/runtime/time.go:188 +0xbf
fyne.io/fyne/internal/painter.svgCacheJanitor.func1()
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/painter/svg_cache.go:57 +0x109
sync.(*Once).doSlow(0x49882c8, 0xc000900030)
        /usr/local/opt/go/libexec/src/sync/once.go:66 +0xec
sync.(*Once).Do(0x49882c8, 0xc000900030)
        /usr/local/opt/go/libexec/src/sync/once.go:57 +0x45
created by fyne.io/fyne/internal/painter.svgCacheJanitor
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/painter/svg_cache.go:55 +0x9b

goroutine 51 [chan receive]:
fyne.io/fyne/app.newAppWithDriver.func1(0xc000026d20, 0xc000940000)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/app/app.go:126 +0x3d
created by fyne.io/fyne/app.newAppWithDriver
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/app/app.go:124 +0x1e8

goroutine 52 [runnable]:
syscall.syscall6(0x42d37c0, 0x6, 0x0, 0x0, 0xc00050b688, 0xa, 0x49883b0, 0x0, 0x0, 0x0)
        /usr/local/opt/go/libexec/src/runtime/sys_darwin.go:85 +0x2e
golang.org/x/sys/unix.kevent(0x6, 0x0, 0x0, 0xc00050b688, 0xa, 0x49883b0, 0x0, 0x0, 0x0)
        /Users/ricardoabreu/go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:275 +0xa6
golang.org/x/sys/unix.Kevent(0x6, 0x0, 0x0, 0x0, 0xc00050b688, 0xa, 0xa, 0x49883b0, 0x0, 0x0, ...)
        /Users/ricardoabreu/go/pkg/mod/golang.org/x/[email protected]/unix/syscall_bsd.go:428 +0x71
github.com/fsnotify/fsnotify.read(0x6, 0xc00050b688, 0xa, 0xa, 0x49883b0, 0xc00050b688, 0x0, 0xa, 0x0, 0x0)
        /Users/ricardoabreu/go/pkg/mod/github.com/fsnotify/[email protected]/kqueue.go:511 +0x6e
github.com/fsnotify/fsnotify.(*Watcher).readEvents(0xc000938060)
        /Users/ricardoabreu/go/pkg/mod/github.com/fsnotify/[email protected]/kqueue.go:274 +0x831
created by github.com/fsnotify/fsnotify.NewWatcher
        /Users/ricardoabreu/go/pkg/mod/github.com/fsnotify/[email protected]/kqueue.go:62 +0x199

goroutine 53 [chan receive]:
fyne.io/fyne/app.watchFile.func1(0xc000938060, 0xc000482480, 0x3a, 0xc0009020c0, 0xc0009020d0)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/app/settings_desktop.go:42 +0x5a
created by fyne.io/fyne/app.watchFile
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/app/settings_desktop.go:41 +0xec

goroutine 66 [select, locked to thread]:
fyne.io/fyne/internal/driver/glfw.(*gLDriver).startDrawThread.func1(0xc00007c140, 0xc000690000, 0xc000692000)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/loop.go:186 +0x1ac
created by fyne.io/fyne/internal/driver/glfw.(*gLDriver).startDrawThread
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/loop.go:182 +0xbd

goroutine 68 [chan receive]:
fyne.io/fyne/internal/driver/glfw.(*glCanvas).setupThemeListener.func1(0xc000690060, 0xc0004bc100)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/canvas.go:462 +0x47
created by fyne.io/fyne/internal/driver/glfw.(*glCanvas).setupThemeListener
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/driver/glfw/canvas.go:460 +0xa6

goroutine 82 [chan receive]:
fyne.io/fyne/internal/painter.SvgCacheMonitorTheme.func1(0xc000690120)
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/painter/svg_cache.go:109 +0x34
created by fyne.io/fyne/internal/painter.SvgCacheMonitorTheme
        /Users/ricardoabreu/go/pkg/mod/fyne.io/[email protected]/internal/painter/svg_cache.go:107 +0x9c

rax    0x0
rbx    0x70000eb3a000
rcx    0x70000eb39dc8
rdx    0x0
rdi    0x9c13
rsi    0x6
rbp    0x70000eb39df0
rsp    0x70000eb39dc8
r8     0x2e
r9     0xcccccccccccccccd
r10    0x70000eb3a000
r11    0x246
r12    0x9c13
r13    0x3d2ee000
r14    0x6
r15    0x16
rip    0x7fff202fa462
rflags 0x246
cs     0x7
fs     0x0
gs     0x0
exit status 2

@zagrodzki
Copy link
Collaborator

I believe this is a bug in your code: you close the context before returning from AbletonPush2Device.Open (https://github.com/txbrown/fyne-push2-example/blob/master/display/display.go#L66) - defer is executed as soon as Open finishes.

We should probably add better error messages for this case.

@txbrown
Copy link
Author

txbrown commented Jan 14, 2021

Omg this is so obvious 🤦🏾‍♂️! I never paid attention to that as it's pretty much a copy pasta from the docs. Yes that was the issue here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants