Open kaypour opened 9 years ago
CC @crawshaw
I am without the right kind of device right now, so I won't be able to try this myself until the weekend.
Please don't override myLib.Events's ref() and call(..) methods, and subclass myLib.Events.Stub. The "Passing target language objects to Go" section in https://golang.org/x/mobile/cmd/gobind shows java example.
We still need to check why this error causes complete phone crash.
Hi Hyangah
Thanks for the tip!
I changed the class according to the example you provided. However, it still produces the same error.
I couldn't reproduce it from my phone (nexus5, android 5.0.1). I will check if I can find samsung galaxy note4 around me tomorrow. What android version does your phone run? Thanks!
Hmm that is strange. I tried it on my new phone (Samsung Galaxy note 4) and on my old phone (Samsung Galaxy S3). Note 4: Runs on Android 5.0.1 (Kernel version: 3.10.40-5077540) S3: Runs on Android 4.3 (Kernel version: 3.0.31-2429075)
I compiled into a .arr file on my Linux distribution using Android API 22 and Java 1.7 (Which version did you use?) Then I added it into my Android studio on my Windows machine. Perhaps I need to both create and develop on the same environment?
Okay, so I did a little bit of digging (was pretty hard since the trace kept resetting for some reason)
I found this following crash report, not sure if it is relevant.
08-05 12:05:18.894 7661-7661/? E/Go﹕ panic: unknown ref 42 08-05 12:05:18.894 7661-7661/? E/Go﹕ [ 08-05 12:05:18.894 7661: 7661 E/Go ] goroutine 17 [running, locked to thread]: 08-05 12:05:18.899 7661-7661/? E/Go﹕ golang.org/x/mobile/bind/seq.(Ref).Get(0x70f7c110, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /home/daniel/go/src/golang.org/x/mobile/bind/seq/ref.go:50 +0x188 08-05 12:05:18.899 7661-7661/? E/Go﹕ /tmp/gomobile-work-896542859/go_myLib.proxyTimer_AddListener(0x70f7c0f0, 0x70f7c0e0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /tmp/gomobile-work-896542859/go_myLib/go_myLibmain.go:52 +0x60 08-05 12:05:18.899 7661-7661/? E/Go﹕ golang.org/x/mobile/bind/java.Send(0x5948cf88, 0xe, 0xc, 0x59636c60, 0x8, 0x594831b0, 0x594831b8) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /home/daniel/go/src/golang.org/x/mobile/bind/java/seq_android.go:39 +0x29c 08-05 12:05:18.899 7661-7661/? E/Go﹕ [ 08-05 12:05:18.899 7661: 7661 E/Go ] goroutine 18 [semacquire, locked to thread]: 08-05 12:05:18.899 7661-7661/? E/Go﹕ sync.runtime_Syncsemacquire(0x60d26e60) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/runtime/sema.go:237 +0x250 08-05 12:05:18.899 7661-7661/? E/Go﹕ sync.(_Cond).Wait(0x60d26e58) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/sync/cond.go:62 +0xbc 08-05 12:05:18.899 7661-7661/? E/Go﹕ golang.org/x/mobile/bind/java.Recv(0x590494e0, 0x590494e8, 0x40b7016f, 0x59049948, 0x5904a7a8) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /home/daniel/go/src/golang.org/x/mobile/bind/java/seq_android.go:110 +0x60 08-05 12:05:18.899 7661-7661/? E/Go﹕ [ 08-05 12:05:18.899 7661: 7661 E/Go ] goroutine 5 [syscall]: 08-05 12:05:18.899 7661-7661/? E/Go﹕ syscall.Syscall(0x3, 0x32, 0x70fbe000, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/syscall/asm_linux_arm.s:17 +0x8 08-05 12:05:18.899 7661-7661/? E/Go﹕ syscall.read(0x32, 0x70fbe000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/syscall/zsyscall_linux_arm.go:783 +0x78 08-05 12:05:18.899 7661-7661/? E/Go﹕ syscall.Read(0x32, 0x70fbe000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/syscall/syscall_unix.go:160 +0x4c 08-05 12:05:18.899 7661-7661/? E/Go﹕ os.(_File).read(0x70f4a158, 0x70fbe000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/os/file_unix.go:211 +0x54 08-05 12:05:18.899 7661-7661/? E/Go﹕ os.(_File).Read(0x70f4a158, 0x70fbe000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/os/file.go:95 +0x7c 08-05 12:05:18.899 7661-7661/? E/Go﹕ bufio.(_Reader).fill(0x70f57f7c) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/bufio/bufio.go:97 +0x1c4 08-05 12:05:18.899 7661-7661/? E/Go﹕ bufio.(_Reader).ReadSlice(0x70f57f7c, 0x40a, 0x0, 0x0, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/bufio/bufio.go:328 +0x264 08-05 12:05:18.899 7661-7661/? E/Go﹕ bufio.(_Reader).ReadLine(0x70f57f7c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/bufio/bufio.go:357 +0x60 08-05 12:05:18.899 7661-7661/? E/Go﹕ golang.org/x/mobile/internal/mobileinit.lineLog(0x70f4a158, 0x6) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /home/daniel/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:50 +0xe0 08-05 12:05:18.899 7661-7661/? E/Go﹕ created by golang.org/x/mobile/internal/mobileinit.init.1 08-05 12:05:18.899 7661-7661/? E/Go﹕ /home/daniel/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:74 +0x104 08-05 12:05:18.899 7661-7661/? E/Go﹕ [ 08-05 12:05:18.899 7661: 7661 E/Go ] goroutine 6 [syscall]: 08-05 12:05:18.899 7661-7661/? E/Go﹕ syscall.Syscall(0x3, 0x34, 0x70fc0000, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/syscall/asm_linux_arm.s:17 +0x8 08-05 12:05:18.899 7661-7661/? E/Go﹕ syscall.read(0x34, 0x70fc0000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/syscall/zsyscall_linux_arm.go:783 +0x78 08-05 12:05:18.899 7661-7661/? E/Go﹕ syscall.Read(0x34, 0x70fc0000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/syscall/syscall_unix.go:160 +0x4c 08-05 12:05:18.899 7661-7661/? E/Go﹕ os.(_File).read(0x70f4a168, 0x70fc0000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.899 7661-7661/? E/Go﹕ /usr/local/go/src/os/file_unix.go:211 +0x54 08-05 12:05:18.904 7661-7661/? E/Go﹕ os.(_File).Read(0x70f4a168, 0x70fc0000, 0x400, 0x400, 0x0, 0x0, 0x0) 08-05 12:05:18.904 7661-7661/? E/Go﹕ /usr/local/go/src/os/file.go:95 +0x7c 08-05 12:05:18.904 7661-7661/? E/Go﹕ bufio.(_Reader).fill(0x70f5877c) 08-05 12:05:18.904 7661-7661/? E/Go﹕ /usr/local/go/src/bufio/bufio.go:97 +0x1c4 08-05 12:05:18.904 7661-7661/? E/Go﹕ bufio.(_Reader).ReadSlice(0x70f5877c, 0x40a, 0x0, 0x0, 0x0, 0x0, 0x0) 08-05 12:05:18.904 7661-7661/? E/Go﹕ /usr/local/go/src/bufio/bufio.go:328 +0x264 08-05 12:05:18.904 7661-7661/? E/Go﹕ bufio.(_Reader).ReadLine(0x70f5877c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) 08-05 12:05:18.904 7661-7661/? E/Go﹕ /usr/local/go/src/bufio/bufio.go:357 +0x60 08-05 12:05:18.904 7661-7661/? E/Go﹕ golang.org/x/mobile/internal/mobileinit.lineLog(0x70f4a168, 0x4) 08-05 12:05:18.904 7661-7661/? E/Go﹕ /home/daniel/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:50 +0xe0 08-05 12:05:18.904 7661-7661/? E/Go﹕ created by golang.org/x/mobile/internal/mobileinit.init.1 08-05 12:05:18.904 7661-7661/? E/Go﹕ /home/daniel/go/src/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go:81 +0x194 08-05 12:05:18.904 7661-7661/? E/Go﹕ [ 08-05 12:05:18.904 7661: 7661 E/Go ] goroutine 19 [syscall, locked to thread]: 08-05 12:05:18.904 7661-7661/? E/Go﹕ runtime.goexit() 08-05 12:05:18.904 7661-7661/? E/Go﹕ /usr/local/go/src/runtime/asm_arm.s:1016 +0x4 08-05 12:05:18.949 2344-2500/? E/InputDispatcher﹕ channel ~ Channel is unrecoverably broken and will be disposed!
Thanks, that is a clear error message from inside gobind. Haven't tracked it down yet.
I couldn't find the same device around me. Instead I checked in the code I tested in https://github.com/hyangah/bugs/tree/master/golang12020 so people with the devices can test, and we all debug the same code. @Opposition can you please check if there is any difference between my code and yours? Thanks!
The 'android' directory is the Android studio project. 'myLib' directory is the go package directory. This assumes the checked in code is under a GOPATH directory.
I am using JDK 1.7.
There is no difference between the code. Thanks for taking your time and putting it on Git :)
So I suppose my code crashes as well in your devices. Very strange because the stack trace shows a path that shouldn't happen at all (ref num 42 means, it's a java object. For java object, seq.Get() shouldn't be called. :-(
Until we have the same device for reproduction, I think the only option we both can try is emulators. I tried the android studio emulator (Nexus 5 API 22 armeabi-7a, Android 5.1) and it worked. So, I guess your code should work with the same emulator.
Good news!
So I went on my Linux environment, did a git clone on your repository, imported it into android studio, compiled the go file into an .arr and added it to the project. Attached my phone and it does not crash anymore.
A screenshot taken by my phone, running the program. Added an infinite loop, just to see it trigger every five seconds.
However, if I build the .arr file on my Linux and use it in Android studio on my Windows machine the problem occurs again. My guess is it is not the fault of the bind mechanism, but something else not go related.
What is the underlying type of the Events instance once passed to the golang side? When passed to the function AddListener(Events)
, is it passing by value or by reference?
I just had the same issue in a very similar setting (panic: unknown ref 42
). I suspect the issue is that a UI element is touched from a non-UI thread.
Instead of handling the ui element directly in a callback (which leads the the above error), this worked for me:
uiElement.post(new Runnable() {
public void run() {
// do stuff with uiElement
}
});
@benma, I can take a look at the root cause if you can provide a self-contained case that demonstrates the crash.
What version of Go are you using (go version)?
go version go1.5beta2 linux/amd64
gomobile version +99196c8 Sat Aug 1 23:05:44 2015 +0000 (android); androidSDK=/usr/local/android-sdk-linux/platforms/android-22
What operating system and processor architecture are you using?
Development: Linux Mint 64bit / Windows 10 64bit on i7 (920) Phone: Samsung Galaxy note 4 on ARMv7
What did you do?
Created a simple go library:
Compiled a .arr file : gomobile bind {folder path}
Added the .arr file to an Android Studio project.
*Red box indicates which method call that crashes the application, during runtime.
What did you expect to see?
The instance of the object getting appended correctly to the Go slice, or to show a stack trace / error message.
What did you see instead?
Passing null as parameter, shows a null value exception. However, the example above shuts the application down on my phone completely, with no exception or stack trace, even in debug mode. Try-catch does not help in this situation.