Skip to content

Commit

Permalink
Fix context thread issues on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Nov 27, 2018
1 parent f515db4 commit d7c1885
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 4 additions & 0 deletions driver/gl/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ func (d *gLDriver) runGL() {

// remove window from window list
d.windows = append(d.windows[:i], d.windows[i+1:]...)
glfw.DetachCurrentContext()
continue
}

if !canvas.isDirty() {
glfw.DetachCurrentContext()
continue
}
win.(*window).fitContent()
Expand All @@ -65,7 +67,9 @@ func (d *gLDriver) runGL() {

gl.Viewport(0, 0, int32(winWidth), int32(winHeight))
canvas.paint(size)

win.(*window).viewport.SwapBuffers()
glfw.DetachCurrentContext()
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions driver/gl/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func (w *window) FullScreen() bool {
}

func (w *window) SetFullScreen(full bool) {
w.viewport.MakeContextCurrent()

w.fullScreen = full
monitor := glfw.GetPrimaryMonitor() // TODO detect if the window is on this one...
mode := monitor.GetVideoMode()
Expand All @@ -60,16 +58,12 @@ func (w *window) FixedSize() bool {
}

func (w *window) SetFixedSize(fixed bool) {
w.viewport.MakeContextCurrent()

w.fixedSize = fixed

w.fitContent()
}

func (w *window) fitContent() {
w.viewport.MakeContextCurrent()

if w.canvas.content == nil {
return
}
Expand Down Expand Up @@ -101,8 +95,6 @@ func scaleForDpi(xdpi int) float32 {
}

func detectScale(win *glfw.Window) float32 {
win.MakeContextCurrent()

env := os.Getenv("FYNE_SCALE")
if env != "" {
scale, _ := strconv.ParseFloat(env, 32)
Expand Down Expand Up @@ -144,8 +136,6 @@ func (w *window) resize(size fyne.Size) {
}

func (w *window) SetContent(content fyne.CanvasObject) {
w.viewport.MakeContextCurrent()

w.canvas.SetContent(content)
min := content.MinSize()
w.canvas.SetScale(detectScale(w.viewport))
Expand All @@ -159,7 +149,6 @@ func (w *window) Canvas() fyne.Canvas {
}

func (w *window) closed(viewport *glfw.Window) {
w.viewport.MakeContextCurrent()
viewport.SetShouldClose(true)

// trigger callbacks
Expand Down Expand Up @@ -426,6 +415,7 @@ func (d *gLDriver) CreateWindow(title string) fyne.Window {
win.SetMouseButtonCallback(ret.mouseClicked)
win.SetKeyCallback(ret.keyPressed)
win.SetCharModsCallback(ret.charModInput)
glfw.DetachCurrentContext()
return ret
}

Expand Down

0 comments on commit d7c1885

Please sign in to comment.