diff --git a/assets/emulator/libretro/cores/mupen64plus_next_libretro.dylib b/assets/emulator/libretro/cores/mupen64plus_next_libretro.dylib new file mode 100755 index 00000000..6bdb8520 Binary files /dev/null and b/assets/emulator/libretro/cores/mupen64plus_next_libretro.dylib differ diff --git a/cmd/worker/main.go b/cmd/worker/main.go index ba6a1368..7a2f1b51 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -7,15 +7,15 @@ import ( "os/signal" "time" + "github.com/faiface/mainthread" config "github.com/giongto35/cloud-game/pkg/config/worker" - "github.com/giongto35/cloud-game/pkg/util/logging" "github.com/giongto35/cloud-game/pkg/worker" "github.com/golang/glog" "github.com/spf13/pflag" ) -func main() { +func run() { rand.Seed(time.Now().UTC().UnixNano()) cfg := config.NewDefaultConfig() @@ -43,3 +43,8 @@ func main() { cancelCtx() } } + +func main() { + // enables mainthread package and runs run in a separate goroutine + mainthread.Run(run) +} diff --git a/go.mod b/go.mod index 00d69a3d..4b9cb116 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.12 require ( cloud.google.com/go v0.43.0 github.com/disintegration/imaging v1.6.2 + github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 github.com/gen2brain/x264-go v0.0.0-20200517120223-c08131f6fc8a github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 github.com/gofrs/uuid v3.2.0+incompatible diff --git a/go.sum b/go.sum index ca697412..620cc1bc 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= +github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 h1:baVdMKlASEHrj19iqjARrPbaRisD7EuZEVJj6ZMLl1Q= +github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3/go.mod h1:VEPNJUlxl5KdWjDvz6Q1l+rJlxF2i6xqDeGuGAxa87M= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gen2brain/x264-go v0.0.0-20200517120223-c08131f6fc8a h1:O6MN0Yik9iXHlC5t/NUznAgt18d0yAKIPZTihxLBIDE= diff --git a/pkg/emulator/libretro/nanoarch/nanoarch.go b/pkg/emulator/libretro/nanoarch/nanoarch.go index 228fd7b5..2917ff0b 100644 --- a/pkg/emulator/libretro/nanoarch/nanoarch.go +++ b/pkg/emulator/libretro/nanoarch/nanoarch.go @@ -13,6 +13,7 @@ import ( "unsafe" "github.com/disintegration/imaging" + "github.com/faiface/mainthread" "github.com/giongto35/cloud-game/pkg/config" "github.com/giongto35/cloud-game/pkg/emulator/libretro/image" "github.com/go-gl/gl/v4.1-core/gl" @@ -367,15 +368,20 @@ func initVideo() { fmt.Println("Unsupported hw context:", video.hw.context_type) } - video.window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_OPENGL) - if err != nil { - panic(err) - } + // In OSX 10.14+ window creation and context creation must happen in the main thread + mainthread.Call(func() { + video.window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_OPENGL) + if err != nil { + panic(err) + } - video.context, err = video.window.GLCreateContext() - if err != nil { - panic(err) - } + video.context, err = video.window.GLCreateContext() + if err != nil { + panic(err) + } + }) + // Bind context to current thread + video.window.GLMakeCurrent(video.context) if err = gl.InitWithProcAddrFunc(sdl.GLGetProcAddress); err != nil { panic(err) @@ -431,13 +437,18 @@ func initVideo() { //export deinitVideo func deinitVideo() { + C.bridge_context_reset(video.hw.context_destroy) if video.hw.depth { gl.DeleteRenderbuffers(1, &video.rbo); } gl.DeleteFramebuffers(1, &video.fbo) gl.DeleteTextures(1, &video.tex) - sdl.GLDeleteContext(video.context) - video.window.Destroy() + // In OSX 10.14+ window deletion must happen in the main thread + mainthread.Call(func() { + video.window.GLMakeCurrent(video.context) + sdl.GLDeleteContext(video.context) + video.window.Destroy() + }) video.isGl = false } @@ -626,7 +637,9 @@ func coreLoadGame(filename string) { if usesLibCo { C.bridge_execute(C.initVideo_cgo) } else { + runtime.LockOSThread() initVideo() + runtime.UnlockOSThread() } } }