Skip to content

Commit

Permalink
shiny/driver/mtldriver: update to GLFW v3.3
Browse files Browse the repository at this point in the history
GLFW v3.2 was old and started generating some warnings on macOS 10.15
Catalina (and warnings get upgraded to errors on builders). Update to
GLFW v3.3 that was recently released to resolve the problem.

There is a small regression affecting the newer version of GLFW that is
being tracked in issues glfw/glfw#1543 and
go-gl/glfw#262. It causes the application to
crash when glfwWaitEvents is called before the first window is opened:

	$ go run -tags='example metal' .../shiny/example/basic
	2019-11-25 22:19:24.715 basic[9412:69556] *** Assertion failure in -[NSApplication run], /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.10.126/AppKit.subproj/NSApplication.m:3313
	2019-11-25 22:19:24.715 basic[9412:69556] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSApp with wrong _running count'
	*** First throw call stack:
	(
		0   CoreFoundation                      0x00007fff30503f53 __exceptionPreprocess + 250
		1   libobjc.A.dylib                     0x00007fff665c9835 objc_exception_throw + 48
		2   CoreFoundation                      0x00007fff3051f810 +[NSException raise:format:arguments:] + 88
		3   Foundation                          0x00007fff32bff5d1 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
		4   AppKit                              0x00007fff2d657ed3 -[NSApplication run] + 1007
		5   basic                               0x00000000040d473d _glfwPlatformCreateWindow + 77
		6   basic                               0x00000000040cd945 glfwCreateWindow + 485
		7   basic                               0x00000000040da71b _cgo_78603e0816ec_Cfunc_glfwCreateWindow + 43
		8   basic                               0x0000000004058430 runtime.asmcgocall + 112
	)
	libc++abi.dylib: terminating with uncaught exception of type NSException
	SIGABRT: abort
	PC=0x7fff67a7b49a m=0 sigcode=0
	signal arrived during cgo execution
	[...]

Work around it by waiting for the first window open request before
entering the main loop. That way, glfwWaitEvents is not called
before a window has been created, and the crash does not occur.
This temporary workaround can be removed after the bug is fixed.

Fixes golang/go#35766
Updates go-gl/glfw#256
Updates glfw/glfw#1543
Updates go-gl/glfw#262

Change-Id: Ie9b15ab6632af39871d94993a3e3097ea798a7e2
Reviewed-on: https://go-review.googlesource.com/c/exp/+/208877
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
dmitshur committed Nov 27, 2019
1 parent 41df830 commit 9964a5a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.12
require (
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028
golang.org/x/mod v0.1.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9 h1:VpgP7xuJadIUu
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 h1:b+9H1GAsx5RsjvDFLoS5zkNBzIQMuVKUYQDmxU3N5XE=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand All @@ -23,8 +23,6 @@ golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e h1:1xWUkZQQ9Z9UuZgNaIR6OQOE7rUFglXUUBZlO+dGg6I=
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a h1:TwMENskLwU2NnWBzrJGEWHqSiGUkO/B4rfyhwqDxDYQ=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
9 changes: 8 additions & 1 deletion shiny/driver/mtldriver/mtldriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"unsafe"

"dmitri.shuralyov.com/gpu/mtl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/go-gl/glfw/v3.3/glfw"
"golang.org/x/exp/shiny/driver/internal/errscreen"
"golang.org/x/exp/shiny/driver/mtldriver/internal/appkit"
"golang.org/x/exp/shiny/driver/mtldriver/internal/coreanim"
Expand Down Expand Up @@ -67,6 +67,13 @@ func main(f func(screen.Screen)) error {
close(done)
glfw.PostEmptyEvent() // Break main loop out of glfw.WaitEvents so it can receive on done.
}()
select {
// TODO(dmitshur): Delete this when https://github.com/go-gl/glfw/issues/262 is resolved.
// Wait for first window request (or done) before entering main
// loop to work around https://github.com/glfw/glfw/issues/1543.
case newWindowCh <- <-newWindowCh:
case <-done:
}
for {
select {
case <-done:
Expand Down
2 changes: 1 addition & 1 deletion shiny/driver/mtldriver/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package mtldriver
import (
"image"

"github.com/go-gl/glfw/v3.2/glfw"
"github.com/go-gl/glfw/v3.3/glfw"
"golang.org/x/exp/shiny/screen"
)

Expand Down
2 changes: 1 addition & 1 deletion shiny/driver/mtldriver/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"log"

"dmitri.shuralyov.com/gpu/mtl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/go-gl/glfw/v3.3/glfw"
"golang.org/x/exp/shiny/driver/internal/drawer"
"golang.org/x/exp/shiny/driver/internal/event"
"golang.org/x/exp/shiny/driver/internal/lifecycler"
Expand Down

0 comments on commit 9964a5a

Please sign in to comment.