mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
shareable: Bug fix: Unexpected allocation when extending an image
Fixes #1028
This commit is contained in:
parent
85cbc7e56b
commit
09ea15e0ff
@ -97,14 +97,15 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nExtended := 1
|
nExtended := 1
|
||||||
|
var n *packing.Node
|
||||||
for {
|
for {
|
||||||
if !b.page.Extend(nExtended) {
|
if !b.page.Extend(nExtended) {
|
||||||
// The page can't be extended any more. Return as failure.
|
// The page can't be extended any more. Return as failure.
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
nExtended++
|
nExtended++
|
||||||
if n := b.page.Alloc(width, height); n != nil {
|
n = b.page.Alloc(width, height)
|
||||||
// The page is just for emulation, so we don't have to free it.
|
if n != nil {
|
||||||
b.page.CommitExtension()
|
b.page.CommitExtension()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -114,7 +115,6 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
|||||||
s := b.page.Size()
|
s := b.page.Size()
|
||||||
b.restorable = b.restorable.Extend(s, s)
|
b.restorable = b.restorable.Extend(s, s)
|
||||||
|
|
||||||
n := b.page.Alloc(width, height)
|
|
||||||
if n == nil {
|
if n == nil {
|
||||||
panic("shareable: Alloc result must not be nil at TryAlloc")
|
panic("shareable: Alloc result must not be nil at TryAlloc")
|
||||||
}
|
}
|
||||||
|
@ -393,4 +393,17 @@ func TestDisposeImmediately(t *testing.T) {
|
|||||||
img1.MarkDisposed()
|
img1.MarkDisposed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #1028
|
||||||
|
func TestExtendWithBigImage(t *testing.T) {
|
||||||
|
img0 := NewImage(1, 1, false)
|
||||||
|
defer img0.MarkDisposed()
|
||||||
|
|
||||||
|
img0.ReplacePixels(make([]byte, 4*1*1))
|
||||||
|
|
||||||
|
img1 := NewImage(1025, 1025, false)
|
||||||
|
defer img1.MarkDisposed()
|
||||||
|
|
||||||
|
img1.ReplacePixels(make([]byte, 4*1025*1025))
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Add tests to extend shareable image out of the main loop
|
// TODO: Add tests to extend shareable image out of the main loop
|
||||||
|
Loading…
Reference in New Issue
Block a user