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

x/mobile/app: gobind crash 'app.Run called on thread xxx, but app.init ran on xx' #27509

Open
ntop001 opened this issue Sep 5, 2018 · 3 comments
Labels
mobile Android, iOS, and x/mobile
Milestone

Comments

@ntop001
Copy link

ntop001 commented Sep 5, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

YES.

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

GOARCH="amd64"
GOBIN="/Users/ntop/tools/go"
GOCACHE="/Users/ntop/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ntop/workspace/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t6/8417qy4n2zn3lb370499nrl00000gn/T/go-build892512347=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm building a Go game for iOS. I use GoMobile's x/mobile/app package to write the game, but I didn't use gomobile build to build an .app. Since gomobile build just build a simple iOS app, if I want to use more native features, that's impossible. So I use gomobile bind to build a .framework, and invoke the 'Start' function in XCode's main method. But it will result in the exception - 'gobind app.Run called on thread xxx, but app.init ran on xx'. In the 'Start' function, I did't use any go routines, just call app.Main() to start the game. I printed thread-id both in init function and the app.Main() function, the thread-id is truely different. It seems that the .framework built with gomobile will not init package in the same thread as the calling function.

What did you expect to see?

The .framework build with gomobile bind can work successfully in my iOS project.
PS: only code use x/mobile/app will crash, because the checking code stay there.

What did you see instead?

The app crashed and print the message as above.

@gopherbot gopherbot added this to the Unreleased milestone Sep 5, 2018
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Sep 5, 2018
ntop001 added a commit to KorokEngine/mobile that referenced this issue Sep 28, 2018
Fixes golang/go#27509
Building a libray for iOS including these code will crash.
@meslienjonathan
Copy link

meslienjonathan commented Jul 5, 2019

@ntop001 I have exactly the same problem did you find a solution ?
if so how did you solve the problem?
thank you in advance

@ntop001
Copy link
Author

ntop001 commented Jul 5, 2019

@meslienjonathan I just comment out some code in main function, you can see my modification here:KorokEngine/mobile@3b142cd
I also fixed some other bugs in gomobile: https://github.com/KorokEngine/mobile/tree/korok

@meslienjonathan
Copy link

@ntop001 awesome it works thank you !

andydotxyz pushed a commit to fyne-io/mobile that referenced this issue Aug 23, 2019
Fixes golang/go#27509
Building a libray for iOS including these code will crash.
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

3 participants