mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
restorable: Refactoring: Disallow nil at ReplacePixels
This commit is contained in:
parent
052697e305
commit
f3fa535afb
@ -306,6 +306,10 @@ func (i *Image) ClearPixels(x, y, width, height int) {
|
|||||||
//
|
//
|
||||||
// If pixels is nil, ReplacePixels clears the specified reagion.
|
// If pixels is nil, ReplacePixels clears the specified reagion.
|
||||||
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
||||||
|
if pixels == nil {
|
||||||
|
panic("restorable: pixels must not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
w, h := i.image.Size()
|
w, h := i.image.Size()
|
||||||
if width <= 0 || height <= 0 {
|
if width <= 0 || height <= 0 {
|
||||||
panic("restorable: width/height must be positive")
|
panic("restorable: width/height must be positive")
|
||||||
@ -318,11 +322,6 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
|
|||||||
// For this purpuse, images should remember which part of that is used for DrawTriangles.
|
// For this purpuse, images should remember which part of that is used for DrawTriangles.
|
||||||
theImages.makeStaleIfDependingOn(i)
|
theImages.makeStaleIfDependingOn(i)
|
||||||
|
|
||||||
if pixels == nil {
|
|
||||||
// TODO: Allocating bytes for all pixels are wasteful. Allocate memory only for required regions
|
|
||||||
// (#897).
|
|
||||||
pixels = make([]byte, 4*width*height)
|
|
||||||
}
|
|
||||||
i.image.ReplacePixels(pixels, x, y, width, height)
|
i.image.ReplacePixels(pixels, x, y, width, height)
|
||||||
|
|
||||||
if !needsRestoring() {
|
if !needsRestoring() {
|
||||||
|
@ -540,7 +540,7 @@ func TestClear(t *testing.T) {
|
|||||||
img := NewImage(4, 4)
|
img := NewImage(4, 4)
|
||||||
img.ReplacePixels(pix, 0, 0, 4, 4)
|
img.ReplacePixels(pix, 0, 0, 4, 4)
|
||||||
// This doesn't make the image stale. Its base pixels are available.
|
// This doesn't make the image stale. Its base pixels are available.
|
||||||
img.ReplacePixels(nil, 1, 1, 2, 2)
|
img.ReplacePixels(make([]byte, 4*4*4), 1, 1, 2, 2)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Index int
|
Index int
|
||||||
|
Loading…
Reference in New Issue
Block a user