mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +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"
|
||||
"math"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"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).
|
||||
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() {
|
||||
return color.RGBA{}
|
||||
}
|
||||
@ -554,6 +559,10 @@ func (i *Image) At(x, y int) color.Color {
|
||||
//
|
||||
// If the image is disposed, Set does nothing.
|
||||
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()
|
||||
if img.isDisposed() {
|
||||
return
|
||||
|
3
run.go
3
run.go
@ -44,6 +44,7 @@ func CurrentFPS() float64 {
|
||||
var (
|
||||
isDrawingSkipped = int32(0)
|
||||
currentMaxTPS = int32(DefaultTPS)
|
||||
isRunning = int32(0)
|
||||
)
|
||||
|
||||
func setDrawingSkipped(skipped bool) {
|
||||
@ -89,6 +90,8 @@ func IsRunningSlowly() bool {
|
||||
var theGraphicsContext atomic.Value
|
||||
|
||||
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.RegularTermination {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user