diff --git a/ebitenutil/debugprint.go b/ebitenutil/debugprint.go index efb2eb565..d153921f1 100644 --- a/ebitenutil/debugprint.go +++ b/ebitenutil/debugprint.go @@ -64,7 +64,7 @@ func DebugPrint(image *ebiten.Image, str string) error { return defaultDebugPrintState.DebugPrint(image, str) } -func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) { +func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) error { ur, ug, ub, ua := c.RGBA() const max = math.MaxUint16 r := float64(ur) / max @@ -81,7 +81,10 @@ func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c col } op.GeoM.Translate(float64(x+1), float64(y)) op.ColorM.Scale(r, g, b, a) - rt.DrawImage(d.textImage, op) + if err := rt.DrawImage(d.textImage, op); err != nil { + return err + } + return nil } // DebugPrint prints the given text str on the given image r. @@ -104,7 +107,11 @@ func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) error { return err } } - d.drawText(r, str, 1, 1, color.NRGBA{0x00, 0x00, 0x00, 0x80}) - d.drawText(r, str, 0, 0, color.NRGBA{0xff, 0xff, 0xff, 0xff}) + if err := d.drawText(r, str, 1, 1, color.NRGBA{0x00, 0x00, 0x00, 0x80}); err != nil { + return err + } + if err := d.drawText(r, str, 0, 0, color.NRGBA{0xff, 0xff, 0xff, 0xff}); err != nil { + return err + } return nil } diff --git a/graphicscontext.go b/graphicscontext.go index 8b8d1b016..10627978f 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -47,13 +47,19 @@ func (c *graphicsContext) GLContext() *opengl.Context { func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale float64) error { if c.screen != nil { - c.screen.Dispose() + if err := c.screen.Dispose(); err != nil { + return err + } } if c.offscreen != nil { - c.offscreen.Dispose() + if err := c.offscreen.Dispose(); err != nil { + return err + } } if c.offscreen2 != nil { - c.offscreen2.Dispose() + if err := c.offscreen2.Dispose(); err != nil { + return err + } } offscreen, err := newVolatileImage(screenWidth, screenHeight, FilterNearest) if err != nil { @@ -74,7 +80,9 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo if err != nil { return err } - c.screen.Clear() + if err := c.screen.Clear(); err != nil { + return err + } c.offscreen = offscreen c.offscreen2 = offscreen2 diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 162724fe0..2e23fff79 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -182,7 +182,9 @@ func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int) geoM: c.geo, colorM: c.color, } - p.begin() + if err := p.begin(); err != nil { + return err + } defer p.end() // TODO: We should call glBindBuffer here? // The buffer is already bound at begin() but it is counterintuitive. diff --git a/internal/graphics/program.go b/internal/graphics/program.go index 5468e2168..92accdbe6 100644 --- a/internal/graphics/program.go +++ b/internal/graphics/program.go @@ -56,7 +56,9 @@ func Reset(context *opengl.Context) error { } func (s *openGLState) reset(context *opengl.Context) error { - context.Reset() + if err := context.Reset(); err != nil { + return err + } s.lastProgram = zeroProgram s.lastProjectionMatrix = nil s.lastModelviewMatrix = nil @@ -132,7 +134,7 @@ type programContext struct { colorM Matrix } -func (p *programContext) begin() { +func (p *programContext) begin() error { c := p.context if p.state.lastProgram != p.program { c.UseProgram(p.program) @@ -215,7 +217,10 @@ func (p *programContext) begin() { // We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture // See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml - c.BindTexture(p.texture) + if err := c.BindTexture(p.texture); err != nil { + return err + } + return nil } func (p *programContext) end() { diff --git a/run.go b/run.go index d485a9231..18c87ed73 100644 --- a/run.go +++ b/run.go @@ -81,7 +81,9 @@ func Run(f func(*Image) error, width, height int, scale float64, title string) e } close(ch) }() - ui.Main() + if err := ui.Main(); err != nil { + return err + } return <-ch }