Skip to content

Commit

Permalink
Revert "Better solution for only running GLFW init once"
Browse files Browse the repository at this point in the history
This reverts commit 460fa8d.
  • Loading branch information
andydotxyz committed Aug 24, 2023
1 parent 4fccfce commit 28ab690
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 1 addition & 3 deletions internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,9 @@ func (d *gLDriver) Run() {
func NewGLDriver() fyne.Driver {
repository.Register("file", intRepo.NewFileRepository())

d := &gLDriver{
return &gLDriver{
done: make(chan interface{}),
drawDone: make(chan interface{}),
animation: &animation.Runner{},
}
d.initGLFW()
return d
}
2 changes: 2 additions & 0 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type runFlag struct {
var funcQueue = make(chan funcData)
var drawFuncQueue = make(chan drawData)
var run = &runFlag{Cond: sync.Cond{L: &sync.Mutex{}}}
var initOnce = &sync.Once{}

// Arrange that main.main runs on main thread.
func init() {
Expand Down Expand Up @@ -105,6 +106,7 @@ func (d *gLDriver) runGL() {
run.L.Unlock()
run.Broadcast()

d.initGLFW()
if d.trayStart != nil {
d.trayStart()
}
Expand Down
18 changes: 10 additions & 8 deletions internal/driver/glfw/loop_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (
)

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

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

initCursors()
d.startDrawThread()
})
}

func (d *gLDriver) tryPollEvents() {
Expand Down
14 changes: 8 additions & 6 deletions internal/driver/glfw/loop_goxjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import (
)

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

d.startDrawThread()
d.startDrawThread()
})
}

func (d *gLDriver) tryPollEvents() {
Expand Down
2 changes: 2 additions & 0 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,8 @@ func (d *gLDriver) createWindow(title string, decorate bool) fyne.Window {
title = defaultTitle
}
runOnMain(func() {
d.initGLFW()

ret = &window{title: title, decorate: decorate, driver: d}
// This queue is destroyed when the window is closed.
ret.InitEventQueue()
Expand Down

0 comments on commit 28ab690

Please sign in to comment.