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

v3.3/glfw: PostEmptyEvent crashes if called first on non-main thread on macOS #272

Open
dmitshur opened this issue Feb 23, 2020 · 2 comments · May be fixed by #400
Open

v3.3/glfw: PostEmptyEvent crashes if called first on non-main thread on macOS #272

dmitshur opened this issue Feb 23, 2020 · 2 comments · May be fixed by #400

Comments

@dmitshur
Copy link
Member

This is the golang.org/go-gl/glfw/v3.3/glfw tracking bug for upstream GLFW issue glfw/glfw#1649. It can be reproduced with the following Go program:

package main

import (
	"log"
	"runtime"

	"github.com/go-gl/glfw/v3.3/glfw"
)

func init() { runtime.LockOSThread() }

func main() {
	err := glfw.Init()
	if err != nil {
		log.Fatalln(err)
	}
	defer glfw.Terminate()

	go glfw.PostEmptyEvent() // call PostEmptyEvent in non-main thread

	select {}
}

Running it on macOS 10.15.3 with Xcode 11.3.1 produces the following crash:


$ go run .                                     
2020-02-22 13:50:10.100 m[22196:92162] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1674.114/Foundation/Misc.subproj/NSUndoManager.m:363
2020-02-22 13:50:10.100 m[22196:92162] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff394778ab __exceptionPreprocess + 250
	1   libobjc.A.dylib                     0x00007fff6f731805 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff394a0d10 +[NSException raise:format:arguments:] + 88
	3   Foundation                          0x00007fff3bb99241 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
	4   Foundation                          0x00007fff3bad7d5e +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 440
	5   AppKit                              0x00007fff365b016c -[NSApplication run] + 864
	6   m                                   0x00000000040b0046 _glfwPlatformPostEmptyEvent + 54
	7   m                                   0x000000000405cc90 runtime.asmcgocall + 112
)
libc++abi.dylib: terminating with uncaught exception of type NSException
SIGABRT: abort
PC=0x7fff70be67fa m=3 sigcode=0

To make progress here, we need to resolve glfw/glfw#1649 first, wait for a new GLFW version with the fix included to be released, and then pull in the fixed GLFW version into golang.org/go-gl/glfw/v3.3/glfw.

@dmitshur
Copy link
Member Author

Note that the crash can be worked around by calling glfw.PostEmptyEvent on main thread first, before it has a chance to be called on non-main thread.

The following does not crash:

func main() {
	err := glfw.Init()
	if err != nil {
		log.Fatalln(err)
	}
	defer glfw.Terminate()

	glfw.PostEmptyEvent()    // call PostEmptyEvent in main thread first
	go glfw.PostEmptyEvent() // call PostEmptyEvent in non-main thread second

	select {}
}

gopherbot pushed a commit to golang/exp that referenced this issue Feb 24, 2020
Update to a newer v3.3/glfw pseudo-version, which uses GLFW 3.3.2.

GLFW 3.3.2 includes a fix for glfw/glfw#1543 (go-gl/glfw#262),
which makes it possible to remove the workaround for it from mtldriver.

However, there is a new regression glfw/glfw#1649 (go-gl/glfw#272).
Fortunately, it's a smaller issue. Add a temporary workaround for it.

Also update comment in two internal packages. The upstream names were
modified in https://dmitri.shuralyov.com/gpu/mtl/...$commit/11308bd612348edeca0d8fddca07bc5a4dfbb35c
to match the names used here.

Change-Id: I3199f16890efd539d62d8914b92260f8a614449a
Reviewed-on: https://go-review.googlesource.com/c/exp/+/220639
Run-TryBot: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Hajime Hoshi <[email protected]>
@pchampio

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants