Skip to content

Commit

Permalink
When window init fails we should quit the app
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Mar 8, 2021
1 parent 3654377 commit e9743e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions internal/driver/glfw/driver.go
Expand Up @@ -3,6 +3,7 @@
package glfw

import (
"os"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -113,6 +114,16 @@ func (d *gLDriver) windowList() []fyne.Window {
return d.windows
}

func (d *gLDriver) initFailed(msg string, err error) {
fyne.LogError(msg, err)

if running() {
d.Quit()
} else {
os.Exit(1)
}
}

func goroutineID() int {
b := make([]byte, 64)
b = b[:runtime.Stack(b, false)]
Expand Down
7 changes: 4 additions & 3 deletions internal/driver/glfw/window.go
Expand Up @@ -57,6 +57,7 @@ type window struct {
cursor desktop.Cursor
customCursor *glfw.Cursor
canvas *glCanvas
driver *gLDriver
title string
icon fyne.Resource
mainmenu *fyne.MainMenu
Expand Down Expand Up @@ -446,7 +447,7 @@ func (w *window) Close() {

func (w *window) ShowAndRun() {
w.Show()
fyne.CurrentApp().Driver().Run()
w.driver.Run()
}

// Clipboard returns the system clipboard
Expand Down Expand Up @@ -1265,7 +1266,7 @@ func (d *gLDriver) createWindow(title string, decorate bool) fyne.Window {
runOnMain(func() {
d.initGLFW()

ret = &window{title: title, decorate: decorate}
ret = &window{title: title, decorate: decorate, driver: d}
// This channel will be closed when the window is closed.
ret.eventQueue = make(chan func(), 1024)
go ret.runEventQueue()
Expand Down Expand Up @@ -1308,7 +1309,7 @@ func (w *window) create() {

win, err := glfw.CreateWindow(pixWidth, pixHeight, w.title, nil, nil)
if err != nil {
fyne.LogError("window creation error", err)
w.driver.initFailed("window creation error", err)
return
}

Expand Down

0 comments on commit e9743e4

Please sign in to comment.