mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 13:07:26 +01:00
Bug fix: Ignore Draw when the window is closed
This commit is contained in:
parent
172dd4bca4
commit
6f1799b1c6
@ -72,12 +72,14 @@ func (w *GameWindow) run(graphicsSharedContext *opengl.SharedContext, sharedGLCo
|
|||||||
w.screenWidth, w.screenHeight, w.screenScale)
|
w.screenWidth, w.screenHeight, w.screenScale)
|
||||||
C.UnuseGLContext()
|
C.UnuseGLContext()
|
||||||
|
|
||||||
w.loop(context, glContext)
|
defer func() {
|
||||||
|
|
||||||
C.UseGLContext(glContext)
|
C.UseGLContext(glContext)
|
||||||
context.Dispose()
|
context.Dispose()
|
||||||
C.UnuseGLContext()
|
C.UnuseGLContext()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
w.loop(context, glContext)
|
||||||
|
}()
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,10 +98,15 @@ func (w *GameWindow) loop(context *opengl.Context, glContext *C.NSOpenGLContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *GameWindow) Draw(f func(graphics.Context)) {
|
func (w *GameWindow) Draw(f func(graphics.Context)) {
|
||||||
|
select {
|
||||||
|
case <-w.closed:
|
||||||
|
return
|
||||||
|
default:
|
||||||
w.useGLContext(func(context *opengl.Context) {
|
w.useGLContext(func(context *opengl.Context) {
|
||||||
context.Update(f)
|
context.Update(f)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *GameWindow) useGLContext(f func(*opengl.Context)) {
|
func (w *GameWindow) useGLContext(f func(*opengl.Context)) {
|
||||||
w.funcs <- f
|
w.funcs <- f
|
||||||
|
Loading…
Reference in New Issue
Block a user