Skip to content

Commit

Permalink
really ensure that GLFW is only initialised once
Browse files Browse the repository at this point in the history
  • Loading branch information
toaster committed Apr 5, 2020
1 parent d1f287c commit 371e12d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 9 additions & 6 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type funcData struct {
var funcQueue = make(chan funcData)
var runFlag = false
var runMutex = &sync.Mutex{}
var initOnce = &sync.Once{}

// Arrange that main.main runs on main thread.
func init() {
Expand Down Expand Up @@ -49,13 +50,15 @@ func runOnMain(f func()) {
}

func (d *gLDriver) initGLFW() {
err := glfw.Init()
if err != nil {
fyne.LogError("failed to initialise GLFW", err)
return
}
initOnce.Do(func() {
err := glfw.Init()
if err != nil {
fyne.LogError("failed to initialise GLFW", err)
return
}

initCursors()
initCursors()
})
}

func (d *gLDriver) tryPollEvents() {
Expand Down
3 changes: 1 addition & 2 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const (

var (
cursorMap map[desktop.Cursor]*glfw.Cursor
initOnce = &sync.Once{}
defaultTitle = "Fyne Application"
)

Expand Down Expand Up @@ -1096,7 +1095,7 @@ func (d *gLDriver) createWindow(title string, decorate bool) fyne.Window {
title = defaultTitle
}
runOnMain(func() {
initOnce.Do(d.initGLFW)
d.initGLFW()

// make the window hidden, we will set it up and then show it later
glfw.WindowHint(glfw.Visible, 0)
Expand Down

0 comments on commit 371e12d

Please sign in to comment.