Skip to content

x/mobile/exp/audio/al: Error when using gomobile bind: no current JVM #15804

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

Open
hajimehoshi opened this issue May 23, 2016 · 2 comments
Open
Labels
mobile Android, iOS, and x/mobile
Milestone

Comments

@hajimehoshi
Copy link
Member

hajimehoshi commented May 23, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.6.2 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

Calling x/mobile/exp/audio/al functions with gomobile bind causes error: al: no current JVM. It seems like init in x/mobile/exp/audio/al is called just before setContext in x/mobile/bind/java/context_android.go is called, which means init in al is called without the JVM context set.

What did you expect to see?

No error.

@hajimehoshi
Copy link
Member Author

Calling x/mobile/exp/audio/al functions with...

Sorry but I meant "calling x/mobile/exp/audio/al functions in an init function with ..."

@quentinmit quentinmit added this to the Unreleased milestone Jun 17, 2016
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 20, 2017
@envsh
Copy link

envsh commented Jun 19, 2018

here only using audio/al package, so need mannual set mobileinit.current_vm and mobileinit.current_ctx global value.
Because mobileinit package is internal, so can we export a function for manually set the value?

this is a works but hacky way,

diff --git a/exp/audio/al/al_android.go b/exp/audio/al/al_android.go
index bce1f8d..dc85b8b 100644
--- a/exp/audio/al/al_android.go
+++ b/exp/audio/al/al_android.go
@@ -242,6 +242,9 @@ var (
        alcDestroyContextFunc     C.LPALCDESTROYCONTEXT
 )
 
+func GetCurrentVMAddr() unsafe.Pointer{return mobileinit.GetCurrentVMAddr()}
+func GetCurrentCtxAddr() unsafe.Pointer{return mobileinit.GetCurrentCtxAddr()}
+
 func initAL() {
        err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error {
                C.al_init(C.uintptr_t(vm), C.uintptr_t(env), C.jobject(ctx), &alHandle)
diff --git a/internal/mobileinit/ctx_android.go b/internal/mobileinit/ctx_android.go
index e0dc166..e0dea81 100644
--- a/internal/mobileinit/ctx_android.go
+++ b/internal/mobileinit/ctx_android.go
@@ -75,6 +75,9 @@ import (
        "unsafe"
 )
 
+func GetCurrentVMAddr() unsafe.Pointer{return unsafe.Pointer(&C.current_vm)}
+func GetCurrentCtxAddr() unsafe.Pointer{return unsafe.Pointer(&C.current_ctx)}
+
 // SetCurrentContext populates the global Context object with the specified
 // current JavaVM instance (vm) and android.context.Context object (ctx).
 // The android.context.Context object must be a global reference.
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

4 participants