mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
graphics: Move locks before manipulating theImages
This commit is contained in:
parent
15e85398e2
commit
bd60f6eb9b
15
image.go
15
image.go
@ -64,6 +64,9 @@ func (i *images) savePixels(context *opengl.Context, exceptions map[*imageImpl]s
|
|||||||
if _, ok := exceptions[img]; ok {
|
if _, ok := exceptions[img]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if img.isDisposed() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := img.savePixels(context); err != nil {
|
if err := img.savePixels(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -196,10 +199,6 @@ func (i *imageImpl) Fill(clr color.Color) error {
|
|||||||
return i.image.Fill(clr)
|
return i.image.Fill(clr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isWholeNumber(x float64) bool {
|
|
||||||
return x == float64(int64(x))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||||
// Calculate vertices before locking because the user can do anything in
|
// Calculate vertices before locking because the user can do anything in
|
||||||
// options.ImageParts interface without deadlock (e.g. Call Image functions).
|
// options.ImageParts interface without deadlock (e.g. Call Image functions).
|
||||||
@ -366,12 +365,12 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
|
|||||||
height: height,
|
height: height,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
}
|
}
|
||||||
|
imageM.Lock()
|
||||||
|
defer imageM.Unlock()
|
||||||
eimg, err := theImages.add(image)
|
eimg, err := theImages.add(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
imageM.Lock()
|
|
||||||
defer imageM.Unlock()
|
|
||||||
image.image, err = graphics.NewImage(width, height, glFilter(ui.GLContext(), filter))
|
image.image, err = graphics.NewImage(width, height, glFilter(ui.GLContext(), filter))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -397,6 +396,8 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
|||||||
height: h,
|
height: h,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
}
|
}
|
||||||
|
imageM.Lock()
|
||||||
|
defer imageM.Unlock()
|
||||||
eimg, err := theImages.add(img)
|
eimg, err := theImages.add(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -409,8 +410,6 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
|||||||
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
|
||||||
}
|
}
|
||||||
imageM.Lock()
|
|
||||||
defer imageM.Unlock()
|
|
||||||
img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter))
|
img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: texture should be removed here?
|
// TODO: texture should be removed here?
|
||||||
|
Loading…
Reference in New Issue
Block a user