Add error checks

This commit is contained in:
Hajime Hoshi 2016-08-02 02:23:23 +09:00
parent 5801bc53df
commit c7106f595c
5 changed files with 37 additions and 13 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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.

View File

@ -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() {

4
run.go
View File

@ -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
}