mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
graphics: Bug fix: Always need to copy the source image
This commit is contained in:
parent
c54dc8ee1c
commit
e5c7de4939
12
imageimpl.go
12
imageimpl.go
@ -61,13 +61,14 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
|||||||
w, h := size.X, size.Y
|
w, h := size.X, size.Y
|
||||||
// TODO: Return error when the image is too big!
|
// TODO: Return error when the image is too big!
|
||||||
// Don't lock while manipulating an image.Image interface.
|
// Don't lock while manipulating an image.Image interface.
|
||||||
rgbaImg, ok := source.(*image.RGBA)
|
|
||||||
if !ok || source.Bounds().Min != image.ZP {
|
// It is necessary to copy the source image since the actual construction of
|
||||||
|
// an image is delayed and we can't expect the source image is not modified
|
||||||
|
// until the construction.
|
||||||
origImg := source
|
origImg := source
|
||||||
newImg := image.NewRGBA(image.Rect(0, 0, w, h))
|
newImg := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||||
draw.Draw(newImg, newImg.Bounds(), origImg, origImg.Bounds().Min, draw.Src)
|
draw.Draw(newImg, newImg.Bounds(), origImg, origImg.Bounds().Min, draw.Src)
|
||||||
rgbaImg = newImg
|
rgbaImg := newImg
|
||||||
}
|
|
||||||
p := make([]uint8, 4*w*h)
|
p := make([]uint8, 4*w*h)
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
copy(p[j*w*4:(j+1)*w*4], rgbaImg.Pix[j*rgbaImg.Stride:])
|
copy(p[j*w*4:(j+1)*w*4], rgbaImg.Pix[j*rgbaImg.Stride:])
|
||||||
@ -218,6 +219,9 @@ func (i *imageImpl) resetPixelsIfDependingOn(target *imageImpl, context *opengl.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
i.pixels.MakeStale()
|
i.pixels.MakeStale()
|
||||||
|
/*if !i.volatile {
|
||||||
|
return errors.New("test")
|
||||||
|
}*/
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user