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