mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
internal/cglfw: let Terminate return an error
This change also removes flushErrors, which is only for GLFW debuggings.
This commit is contained in:
parent
7bcefa1035
commit
6dc375f7a6
@ -119,12 +119,11 @@ func (e *Error) Error() string {
|
|||||||
// Note: There are many cryptic caveats to proper error handling here.
|
// Note: There are many cryptic caveats to proper error handling here.
|
||||||
// See: https://github.com/go-gl/glfw3/pull/86
|
// See: https://github.com/go-gl/glfw3/pull/86
|
||||||
|
|
||||||
// Holds the value of the last error.
|
// lastError holds the value of the last error.
|
||||||
var lastError = make(chan *Error, 1)
|
var lastError = make(chan *Error, 1)
|
||||||
|
|
||||||
//export goErrorCB
|
//export goErrorCB
|
||||||
func goErrorCB(code C.int, desc *C.char) {
|
func goErrorCB(code C.int, desc *C.char) {
|
||||||
flushErrors()
|
|
||||||
err := &Error{ErrorCode(code), C.GoString(desc)}
|
err := &Error{ErrorCode(code), C.GoString(desc)}
|
||||||
select {
|
select {
|
||||||
case lastError <- err:
|
case lastError <- err:
|
||||||
@ -139,28 +138,6 @@ func init() {
|
|||||||
C.glfwSetErrorCallbackCB()
|
C.glfwSetErrorCallbackCB()
|
||||||
}
|
}
|
||||||
|
|
||||||
// flushErrors is called by Terminate before it actually calls C.glfwTerminate,
|
|
||||||
// this ensures that any uncaught errors buffered in lastError are printed
|
|
||||||
// before the program exits.
|
|
||||||
func flushErrors() {
|
|
||||||
err := fetchError()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, "GLFW: An uncaught error has occurred:", err)
|
|
||||||
fmt.Fprintln(os.Stderr, "GLFW: Please report this bug in the Go package immediately.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetchError fetches the next error from the error channel, it does not block
|
|
||||||
// and returns nil if there is no error present.
|
|
||||||
func fetchError() *Error {
|
|
||||||
select {
|
|
||||||
case err := <-lastError:
|
|
||||||
return err
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetchErrorIgnoringPlatformError is fetchError igoring platformError.
|
// fetchErrorIgnoringPlatformError is fetchError igoring platformError.
|
||||||
func fetchErrorIgnoringPlatformError() error {
|
func fetchErrorIgnoringPlatformError() error {
|
||||||
select {
|
select {
|
||||||
|
@ -10,7 +10,10 @@ package cglfw
|
|||||||
//#define GLFW_INCLUDE_NONE
|
//#define GLFW_INCLUDE_NONE
|
||||||
//#include "glfw3_unix.h"
|
//#include "glfw3_unix.h"
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
// Version constants.
|
// Version constants.
|
||||||
const (
|
const (
|
||||||
@ -56,9 +59,12 @@ func Init() error {
|
|||||||
// this function, as it is called by Init before it returns failure.
|
// this function, as it is called by Init before it returns failure.
|
||||||
//
|
//
|
||||||
// This function may only be called from the main thread.
|
// This function may only be called from the main thread.
|
||||||
func Terminate() {
|
func Terminate() error {
|
||||||
flushErrors()
|
|
||||||
C.glfwTerminate()
|
C.glfwTerminate()
|
||||||
|
if err := fetchErrorIgnoringPlatformError(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitHint function sets hints for the next initialization of GLFW.
|
// InitHint function sets hints for the next initialization of GLFW.
|
||||||
|
@ -353,8 +353,7 @@ func SwapInterval(interval int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Terminate() error {
|
func Terminate() error {
|
||||||
cglfw.Terminate()
|
return cglfw.Terminate()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func WaitEvents() error {
|
func WaitEvents() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user