Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When window init fails we should quit the app #2071

Merged
merged 1 commit into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
fpabl0 marked this conversation as resolved.
Show resolved Hide resolved
}
}

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