mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
Bug fix: we can't draw on a window after closing
This commit is contained in:
parent
0c51a7a362
commit
f4e59293fb
@ -25,6 +25,7 @@ type Window struct {
|
|||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
screenScale int
|
screenScale int
|
||||||
|
closed bool
|
||||||
native unsafe.Pointer
|
native unsafe.Pointer
|
||||||
canvas *opengl.Canvas
|
canvas *opengl.Canvas
|
||||||
funcs chan func()
|
funcs chan func()
|
||||||
@ -40,6 +41,7 @@ func runWindow(ui *UI, width, height, scale int, title string, sharedContext uns
|
|||||||
screenWidth: width,
|
screenWidth: width,
|
||||||
screenHeight: height,
|
screenHeight: height,
|
||||||
screenScale: scale,
|
screenScale: scale,
|
||||||
|
closed: false,
|
||||||
funcs: make(chan func()),
|
funcs: make(chan func()),
|
||||||
funcsDone: make(chan struct{}),
|
funcsDone: make(chan struct{}),
|
||||||
}
|
}
|
||||||
@ -80,6 +82,9 @@ func (w *Window) loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) Draw(f func(graphics.Canvas)) {
|
func (w *Window) Draw(f func(graphics.Canvas)) {
|
||||||
|
if w.closed {
|
||||||
|
return
|
||||||
|
}
|
||||||
w.useContext(func() {
|
w.useContext(func() {
|
||||||
w.ui.graphicsDevice.Update(w.canvas, f)
|
w.ui.graphicsDevice.Update(w.canvas, f)
|
||||||
})
|
})
|
||||||
@ -127,5 +132,6 @@ func ebiten_InputUpdated(nativeWindow unsafe.Pointer, inputType C.InputType, cx,
|
|||||||
//export ebiten_WindowClosed
|
//export ebiten_WindowClosed
|
||||||
func ebiten_WindowClosed(nativeWindow unsafe.Pointer) {
|
func ebiten_WindowClosed(nativeWindow unsafe.Pointer) {
|
||||||
w := windows[nativeWindow]
|
w := windows[nativeWindow]
|
||||||
|
w.closed = true
|
||||||
w.notifyWindowClosed(ui.WindowClosedEvent{})
|
w.notifyWindowClosed(ui.WindowClosedEvent{})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user