mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Forbid nil at ReplacePixels explicitly
This commit is contained in:
parent
1f538af440
commit
1a54ff34e6
5
image.go
5
image.go
@ -15,6 +15,7 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"math"
|
||||
@ -616,6 +617,10 @@ func (i *Image) ReplacePixels(p []byte) error {
|
||||
if i.isSubimage() {
|
||||
panic("render to a subimage is not implemented")
|
||||
}
|
||||
s := i.Bounds().Size()
|
||||
if l := 4 * s.X * s.Y; len(p) != l {
|
||||
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", len(p), l))
|
||||
}
|
||||
i.mipmap.original().ReplacePixels(p)
|
||||
i.disposeMipmaps()
|
||||
return nil
|
||||
|
@ -368,6 +368,22 @@ func TestImageReplacePixels(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageReplacePixelsNil(t *testing.T) {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Errorf("ReplacePixels(nil) must panic")
|
||||
}
|
||||
}()
|
||||
|
||||
img, err := NewImage(16, 16, FilterNearest)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
img.Fill(color.White)
|
||||
img.ReplacePixels(nil)
|
||||
}
|
||||
|
||||
func TestImageDispose(t *testing.T) {
|
||||
img, err := NewImage(16, 16, FilterNearest)
|
||||
if err != nil {
|
||||
@ -799,7 +815,7 @@ func TestImageSize4096(t *testing.T) {
|
||||
func TestImageCopy(t *testing.T) {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
t.Errorf("copying image and using it should panic")
|
||||
t.Errorf("copying image and using it must panic")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
package shareable
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"runtime"
|
||||
@ -259,7 +258,7 @@ func (i *Image) replacePixels(p []byte) {
|
||||
x, y, w, h := i.region()
|
||||
if p != nil {
|
||||
if l := 4 * w * h; len(p) != l {
|
||||
panic(fmt.Sprintf("shareable: len(p) was %d but must be %d", len(p), l))
|
||||
panic("not reached")
|
||||
}
|
||||
}
|
||||
i.backend.restorable.ReplacePixels(p, x, y, w, h)
|
||||
|
Loading…
Reference in New Issue
Block a user