From 283c8d41caf1e1e952c8a51d69fb7ef25dacd1c0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 4 Mar 2017 12:02:41 +0900 Subject: [PATCH] ebitenutil: DebugText always returns nil (#331) --- ebitenutil/debugprint.go | 39 +++++++++------------------- ebitenutil/internal/assets/assets.go | 12 ++++----- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/ebitenutil/debugprint.go b/ebitenutil/debugprint.go index d153921f1..854d82fdd 100644 --- a/ebitenutil/debugprint.go +++ b/ebitenutil/debugprint.go @@ -60,11 +60,14 @@ type debugPrintState struct { var defaultDebugPrintState = &debugPrintState{} // DebugPrint draws the string str on the image. +// +// DebugPrint always returns nil as of 1.5.0-alpha. func DebugPrint(image *ebiten.Image, str string) error { - return defaultDebugPrintState.DebugPrint(image, str) + defaultDebugPrintState.DebugPrint(image, str) + return nil } -func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) error { +func (d *debugPrintState) drawText(rt *ebiten.Image, str string, x, y int, c color.Color) { ur, ug, ub, ua := c.RGBA() const max = math.MaxUint16 r := float64(ur) / max @@ -81,37 +84,19 @@ 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) - if err := rt.DrawImage(d.textImage, op); err != nil { - return err - } - return nil + _ = rt.DrawImage(d.textImage, op) } // DebugPrint prints the given text str on the given image r. -func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) error { +func (d *debugPrintState) DebugPrint(r *ebiten.Image, str string) { if d.textImage == nil { - img, err := assets.TextImage() - if err != nil { - return err - } - d.textImage, err = ebiten.NewImageFromImage(img, ebiten.FilterNearest) - if err != nil { - return err - } + img := assets.TextImage() + d.textImage, _ = ebiten.NewImageFromImage(img, ebiten.FilterNearest) } if d.debugPrintRenderTarget == nil { width, height := 256, 256 - var err error - d.debugPrintRenderTarget, err = ebiten.NewImage(width, height, ebiten.FilterNearest) - if err != nil { - return err - } + d.debugPrintRenderTarget, _ = ebiten.NewImage(width, height, ebiten.FilterNearest) } - 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 + d.drawText(r, str, 1, 1, color.NRGBA{0x00, 0x00, 0x00, 0x80}) + d.drawText(r, str, 0, 0, color.NRGBA{0xff, 0xff, 0xff, 0xff}) } diff --git a/ebitenutil/internal/assets/assets.go b/ebitenutil/internal/assets/assets.go index 8efe8a0a0..064f44461 100644 --- a/ebitenutil/internal/assets/assets.go +++ b/ebitenutil/internal/assets/assets.go @@ -19,6 +19,7 @@ package assets import ( "bytes" + "fmt" "image" _ "image/png" ) @@ -30,14 +31,11 @@ const ( TextImageCharHeight = TextImageHeight / 8 ) -func TextImage() (image.Image, error) { - b, err := Asset("text.png") - if err != nil { - return nil, err - } +func TextImage() image.Image { + b := MustAsset("text.png") img, _, err := image.Decode(bytes.NewBuffer(b)) if err != nil { - return nil, err + panic(fmt.Sprintf("assets: image.Decode failed, %v", err)) } - return img, nil + return img }