Skip to content

Commit

Permalink
Specialize goroutineID instead of Run.
Browse files Browse the repository at this point in the history
This should fix #2780
  • Loading branch information
Cedric BAIL committed Apr 28, 2022
1 parent 8d89963 commit 59f0dfe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
15 changes: 5 additions & 10 deletions internal/driver/glfw/driver.go
Expand Up @@ -7,8 +7,6 @@ import (
"image"
"os"
"runtime"
"strconv"
"strings"
"sync"

ico "github.com/Kodeworks/golang-image-ico"
Expand Down Expand Up @@ -151,14 +149,11 @@ func (d *gLDriver) initFailed(msg string, err error) {
}
}

func goroutineID() int {
b := make([]byte, 64)
b = b[:runtime.Stack(b, false)]
// string format expects "goroutine X [running..."
id := strings.Split(strings.TrimSpace(string(b)), " ")[1]

num, _ := strconv.Atoi(id)
return num
func (d *gLDriver) Run() {
if goroutineID() != mainGoroutineID {
panic("Run() or ShowAndRun() must be called from main goroutine")
}
d.runGL()
}

// NewGLDriver sets up a new Driver instance implemented using the GLFW Go library and OpenGL bindings.
Expand Down
17 changes: 12 additions & 5 deletions internal/driver/glfw/driver_desktop.go
Expand Up @@ -4,17 +4,24 @@
package glfw

import (
"runtime"
"strconv"
"strings"

"fyne.io/systray"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)

func (d *gLDriver) Run() {
if goroutineID() != mainGoroutineID {
panic("Run() or ShowAndRun() must be called from main goroutine")
}
d.runGL()
func goroutineID() int {
b := make([]byte, 64)
b = b[:runtime.Stack(b, false)]
// string format expects "goroutine X [running..."
id := strings.Split(strings.TrimSpace(string(b)), " ")[1]

num, _ := strconv.Atoi(id)
return num
}

func (d *gLDriver) SetSystemTrayMenu(m *fyne.Menu) {
Expand Down
4 changes: 2 additions & 2 deletions internal/driver/glfw/driver_goxjs.go
Expand Up @@ -3,6 +3,6 @@

package glfw

func (d *gLDriver) Run() {
d.runGL()
func goroutineID() int {
return mainGoroutineID
}

0 comments on commit 59f0dfe

Please sign in to comment.