mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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.
|
||||
// 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)
|
||||
|
||||
//export goErrorCB
|
||||
func goErrorCB(code C.int, desc *C.char) {
|
||||
flushErrors()
|
||||
err := &Error{ErrorCode(code), C.GoString(desc)}
|
||||
select {
|
||||
case lastError <- err:
|
||||
@ -139,28 +138,6 @@ func init() {
|
||||
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.
|
||||
func fetchErrorIgnoringPlatformError() error {
|
||||
select {
|
||||
|
@ -10,7 +10,10 @@ package cglfw
|
||||
//#define GLFW_INCLUDE_NONE
|
||||
//#include "glfw3_unix.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Version constants.
|
||||
const (
|
||||
@ -56,9 +59,12 @@ func Init() error {
|
||||
// this function, as it is called by Init before it returns failure.
|
||||
//
|
||||
// This function may only be called from the main thread.
|
||||
func Terminate() {
|
||||
flushErrors()
|
||||
func Terminate() error {
|
||||
C.glfwTerminate()
|
||||
if err := fetchErrorIgnoringPlatformError(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitHint function sets hints for the next initialization of GLFW.
|
||||
|
@ -353,8 +353,7 @@ func SwapInterval(interval int) error {
|
||||
}
|
||||
|
||||
func Terminate() error {
|
||||
cglfw.Terminate()
|
||||
return nil
|
||||
return cglfw.Terminate()
|
||||
}
|
||||
|
||||
func WaitEvents() error {
|
||||
|
Loading…
Reference in New Issue
Block a user