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,11 +72,13 @@ 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)
context.Dispose()
C.UnuseGLContext()
}()
C.UseGLContext(glContext) w.loop(context, glContext)
context.Dispose()
C.UnuseGLContext()
}() }()
<-ch <-ch
} }
@ -96,9 +98,14 @@ 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)) {
w.useGLContext(func(context *opengl.Context) { select {
context.Update(f) case <-w.closed:
}) return
default:
w.useGLContext(func(context *opengl.Context) {
context.Update(f)
})
}
} }
func (w *GameWindow) useGLContext(f func(*opengl.Context)) { func (w *GameWindow) useGLContext(f func(*opengl.Context)) {