mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/packing: bug fix: node's links were not synced correctly
Closes #2584
This commit is contained in:
parent
5e4652c4f8
commit
6b957063d4
@ -318,7 +318,8 @@ func (p *Page) extend(newWidth int, newHeight int) func() {
|
||||
var rollback func()
|
||||
|
||||
if aborted {
|
||||
origRoot := *p.root
|
||||
origRoot := p.root
|
||||
origRootCloned := *p.root
|
||||
|
||||
// Extend the page in the vertical direction.
|
||||
if newHeight-p.height > 0 {
|
||||
@ -366,7 +367,10 @@ func (p *Page) extend(newWidth int, newHeight int) func() {
|
||||
rollback = func() {
|
||||
p.width = origWidth
|
||||
p.height = origHeight
|
||||
p.root = &origRoot
|
||||
// The node address must not be changed, so use the original root node's pointer (#2584).
|
||||
// As the root node might be modified, recover the content from the cloned content.
|
||||
p.root = origRoot
|
||||
*p.root = origRootCloned
|
||||
}
|
||||
} else {
|
||||
origWidth, origHeight := p.width, p.height
|
||||
|
@ -431,3 +431,23 @@ func TestExtend3(t *testing.T) {
|
||||
p.Free(n1)
|
||||
p.Free(n2)
|
||||
}
|
||||
|
||||
// Issue #2584
|
||||
func TestRemoveAtRootsChild(t *testing.T) {
|
||||
p := packing.NewPage(32, 32, 1024)
|
||||
n0 := p.Alloc(18, 18)
|
||||
n1 := p.Alloc(28, 59)
|
||||
n2 := p.Alloc(18, 18)
|
||||
n3 := p.Alloc(18, 18)
|
||||
n4 := p.Alloc(8, 10)
|
||||
n5 := p.Alloc(322, 242)
|
||||
_ = n5
|
||||
p.Free(n0)
|
||||
p.Free(n2)
|
||||
p.Free(n1)
|
||||
p.Free(n3)
|
||||
p.Free(n4)
|
||||
|
||||
n6 := p.Alloc(18, 18)
|
||||
p.Free(n6)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user