mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
internal/atlas: bug fix: respect injected maxSize for testings
This commit is contained in:
parent
7c458f519e
commit
03567f74f9
@ -745,6 +745,10 @@ func (i *Image) allocate(putOnAtlas bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !putOnAtlas || !i.canBePutOnAtlas() {
|
if !putOnAtlas || !i.canBePutOnAtlas() {
|
||||||
|
if i.width+2*i.paddingSize() > maxSize || i.height+2*i.paddingSize() > maxSize {
|
||||||
|
panic(fmt.Sprintf("atlas: the image being put on an atlas is too big: width: %d, height: %d", i.width, i.height))
|
||||||
|
}
|
||||||
|
|
||||||
typ := restorable.ImageTypeRegular
|
typ := restorable.ImageTypeRegular
|
||||||
if i.imageType == ImageTypeVolatile {
|
if i.imageType == ImageTypeVolatile {
|
||||||
typ = restorable.ImageTypeVolatile
|
typ = restorable.ImageTypeVolatile
|
||||||
@ -815,8 +819,14 @@ func BeginFrame(graphicsDriver graphicsdriver.Graphics) error {
|
|||||||
if len(theBackends) != 0 {
|
if len(theBackends) != 0 {
|
||||||
panic("atlas: all the images must be not on an atlas before the game starts")
|
panic("atlas: all the images must be not on an atlas before the game starts")
|
||||||
}
|
}
|
||||||
minSize = 1024
|
|
||||||
maxSize = restorable.MaxImageSize(graphicsDriver)
|
// minSize and maxSize can already be set for testings.
|
||||||
|
if minSize == 0 {
|
||||||
|
minSize = 1024
|
||||||
|
}
|
||||||
|
if maxSize == 0 {
|
||||||
|
maxSize = restorable.MaxImageSize(graphicsDriver)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -561,6 +561,21 @@ func Disable_TestMinImageSize(t *testing.T) {
|
|||||||
img.ReplacePixels(make([]byte, 4*s*s), nil)
|
img.ReplacePixels(make([]byte, 4*s*s), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMaxImageSizeExceeded(t *testing.T) {
|
||||||
|
// This tests that a too-big image is allocated correctly.
|
||||||
|
s := maxImageSizeForTesting
|
||||||
|
img := atlas.NewImage(s+1, s, atlas.ImageTypeRegular)
|
||||||
|
defer img.MarkDisposed()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err == nil {
|
||||||
|
t.Errorf("ReplacePixels must panic but not")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
img.ReplacePixels(make([]byte, 4*(s+1)*s), nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Issue #1421
|
// Issue #1421
|
||||||
func TestDisposedAndReputOnAtlas(t *testing.T) {
|
func TestDisposedAndReputOnAtlas(t *testing.T) {
|
||||||
const size = 16
|
const size = 16
|
||||||
|
Loading…
Reference in New Issue
Block a user