Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@dmitshur

Description

@dmitshur

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions