Bug fix: Ignore Draw when the window is closed

This commit is contained in:
Hajime Hoshi 2014-01-11 14:48:43 +09:00
parent 172dd4bca4
commit 6f1799b1c6

View File

@ -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