mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/ui: catch the error at At correctly
This commit is contained in:
parent
df2133186d
commit
9c6b7aaca3
5
image.go
5
image.go
@ -717,6 +717,11 @@ func (i *Image) RGBA64At(x, y int) color.RGBA64 {
|
||||
}
|
||||
|
||||
func (i *Image) at(x, y int) (r, g, b, a uint8) {
|
||||
// Check the error existence and avoid unnecessary calls.
|
||||
if ui.HasError() {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
|
||||
if i.isDisposed() {
|
||||
return 0, 0, 0, 0
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (c *contextImpl) forceUpdateFrame(outsideWidth, outsideHeight float64, devi
|
||||
}
|
||||
|
||||
func (c *contextImpl) updateFrameImpl(updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error {
|
||||
if err := theGlobalState.err(); err != nil {
|
||||
if err := theGlobalState.error(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -102,6 +102,10 @@ func (c *contextImpl) updateFrameImpl(updateCount int, outsideWidth, outsideHeig
|
||||
if err := c.game.Update(); err != nil {
|
||||
return err
|
||||
}
|
||||
// Catch the error that happened at (*Image).At.
|
||||
if err := theGlobalState.error(); err != nil {
|
||||
return err
|
||||
}
|
||||
Get().resetForTick()
|
||||
}
|
||||
|
||||
@ -177,7 +181,7 @@ type globalState struct {
|
||||
screenFilterEnabled_ int32
|
||||
}
|
||||
|
||||
func (g *globalState) err() error {
|
||||
func (g *globalState) error() error {
|
||||
err, ok := g.err_.Load().(error)
|
||||
if !ok {
|
||||
return nil
|
||||
@ -238,6 +242,10 @@ func (g *globalState) setScreenFilterEnabled(enabled bool) {
|
||||
atomic.StoreInt32(&g.screenFilterEnabled_, v)
|
||||
}
|
||||
|
||||
func HasError() bool {
|
||||
return theGlobalState.error() != nil
|
||||
}
|
||||
|
||||
func SetError(err error) {
|
||||
theGlobalState.setError(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user