graphics: Return errors when GLContext is missing

This commit is contained in:
Hajime Hoshi 2016-07-23 22:24:40 +09:00
parent 121063ee2b
commit 806eb44258
2 changed files with 5 additions and 3 deletions

View File

@ -25,7 +25,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
"github.com/hajimehoshi/ebiten/internal/loop"
)
type imageImpl struct {
@ -184,7 +183,7 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
}
func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
if !loop.IsRunning() {
if context == nil {
panic("ebiten: At can't be called when the GL context is not initialized (this panic happens as of version 1.4.0-alpha)")
}
i.m.Lock()

View File

@ -15,6 +15,7 @@
package ebiten
import (
"errors"
"image"
"image/color"
@ -91,7 +92,9 @@ func (p *pixels) hasHistoryWith(target *Image) bool {
}
func (p *pixels) resetHistoryIfNeeded(image *graphics.Image, target *Image, context *opengl.Context) error {
// TODO: Return error when the main loop is not running yet.
if context == nil {
return errors.New("ebiten: OpenGL context is missing: before running the main loop, it is forbidden to manipulate images that is used as a drawing source once.")
}
if p.drawImageHistory == nil {
return nil
}