mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
graphics: Better error message for At and Set (#790)
This commit is contained in:
parent
dd59d8ae6e
commit
58cc5cb105
9
image.go
9
image.go
@ -20,6 +20,7 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/internal/shareable"
|
"github.com/hajimehoshi/ebiten/internal/shareable"
|
||||||
@ -535,6 +536,10 @@ func (i *Image) ColorModel() color.Model {
|
|||||||
//
|
//
|
||||||
// At can't be called outside the main loop (ebiten.Run's updating function) starts (as of version 1.4.0-alpha).
|
// At can't be called outside the main loop (ebiten.Run's updating function) starts (as of version 1.4.0-alpha).
|
||||||
func (i *Image) At(x, y int) color.Color {
|
func (i *Image) At(x, y int) color.Color {
|
||||||
|
if atomic.LoadInt32(&isRunning) == 0 {
|
||||||
|
panic("ebiten: (*Image).At is not available outside the main loop so far")
|
||||||
|
}
|
||||||
|
|
||||||
if i.isDisposed() {
|
if i.isDisposed() {
|
||||||
return color.RGBA{}
|
return color.RGBA{}
|
||||||
}
|
}
|
||||||
@ -554,6 +559,10 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
//
|
//
|
||||||
// If the image is disposed, Set does nothing.
|
// If the image is disposed, Set does nothing.
|
||||||
func (img *Image) Set(x, y int, clr color.Color) {
|
func (img *Image) Set(x, y int, clr color.Color) {
|
||||||
|
if atomic.LoadInt32(&isRunning) == 0 {
|
||||||
|
panic("ebiten: (*Image).Set is not available outside the main loop so far")
|
||||||
|
}
|
||||||
|
|
||||||
img.copyCheck()
|
img.copyCheck()
|
||||||
if img.isDisposed() {
|
if img.isDisposed() {
|
||||||
return
|
return
|
||||||
|
3
run.go
3
run.go
@ -44,6 +44,7 @@ func CurrentFPS() float64 {
|
|||||||
var (
|
var (
|
||||||
isDrawingSkipped = int32(0)
|
isDrawingSkipped = int32(0)
|
||||||
currentMaxTPS = int32(DefaultTPS)
|
currentMaxTPS = int32(DefaultTPS)
|
||||||
|
isRunning = int32(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
func setDrawingSkipped(skipped bool) {
|
func setDrawingSkipped(skipped bool) {
|
||||||
@ -89,6 +90,8 @@ func IsRunningSlowly() bool {
|
|||||||
var theGraphicsContext atomic.Value
|
var theGraphicsContext atomic.Value
|
||||||
|
|
||||||
func run(width, height int, scale float64, title string, g *graphicsContext, mainloop bool) error {
|
func run(width, height int, scale float64, title string, g *graphicsContext, mainloop bool) error {
|
||||||
|
atomic.StoreInt32(&isRunning, 1)
|
||||||
|
defer atomic.StoreInt32(&isRunning, 0)
|
||||||
if err := ui.Run(width, height, scale, title, g, mainloop); err != nil {
|
if err := ui.Run(width, height, scale, title, g, mainloop); err != nil {
|
||||||
if err == ui.RegularTermination {
|
if err == ui.RegularTermination {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user