mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: Bug fix: Don't touch pixelsToSet when disposing a subimage
This change also removes finalizer for subimages since this is not necessary. Fixes #823
This commit is contained in:
parent
dbe4f27d5f
commit
8934f8296f
4
image.go
4
image.go
@ -505,9 +505,7 @@ func (i *Image) SubImage(r image.Rectangle) image.Image {
|
||||
} else {
|
||||
img.original = i
|
||||
}
|
||||
|
||||
img.addr = img
|
||||
runtime.SetFinalizer(img, (*Image).Dispose)
|
||||
|
||||
r = r.Intersect(img.Bounds())
|
||||
// Need to check Empty explicitly. See the standard image package implementations.
|
||||
@ -637,8 +635,8 @@ func (i *Image) Dispose() error {
|
||||
}
|
||||
if !i.isSubimage() {
|
||||
i.mipmap.dispose()
|
||||
i.resolvePixelsToSet(false)
|
||||
}
|
||||
i.resolvePixelsToSet(false)
|
||||
runtime.SetFinalizer(i, nil)
|
||||
return nil
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
_ "image/png"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
. "github.com/hajimehoshi/ebiten"
|
||||
@ -1595,3 +1596,24 @@ func TestImageDrawTrianglesWithSubImage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue #823
|
||||
func TestImageAtAfterDisposingSubImage(t *testing.T) {
|
||||
img, _ := NewImage(16, 16, FilterDefault)
|
||||
img.Set(0, 0, color.White)
|
||||
img.SubImage(image.Rect(0, 0, 16, 16))
|
||||
runtime.GC()
|
||||
got := img.At(0, 0)
|
||||
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
|
||||
if got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
|
||||
img.Set(0, 1, color.White)
|
||||
sub := img.SubImage(image.Rect(0, 0, 16, 16)).(*Image)
|
||||
sub.Dispose()
|
||||
got = img.At(0, 1)
|
||||
if got != want {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user