mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
Simplify internal API not to return errors
This commit is contained in:
parent
7ba18a5d0d
commit
2c5ee99769
28
image.go
28
image.go
@ -45,13 +45,13 @@ var theImagesForRestoring = images{
|
|||||||
images: map[*imageImpl]struct{}{},
|
images: map[*imageImpl]struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) add(img *imageImpl) (*Image, error) {
|
func (i *images) add(img *imageImpl) *Image {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
i.images[img] = struct{}{}
|
i.images[img] = struct{}{}
|
||||||
eimg := &Image{img}
|
eimg := &Image{img}
|
||||||
runtime.SetFinalizer(eimg, theImagesForRestoring.remove)
|
runtime.SetFinalizer(eimg, theImagesForRestoring.remove)
|
||||||
return eimg, nil
|
return eimg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) remove(img *Image) {
|
func (i *images) remove(img *Image) {
|
||||||
@ -265,11 +265,7 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
img.Fill(color.Transparent)
|
img.Fill(color.Transparent)
|
||||||
eimg, err := theImagesForRestoring.add(img)
|
return theImagesForRestoring.add(img), nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return eimg, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newVolatileImage returns an empty 'volatile' image.
|
// newVolatileImage returns an empty 'volatile' image.
|
||||||
@ -289,11 +285,7 @@ func newVolatileImage(width, height int, filter Filter) (*Image, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
img.Fill(color.Transparent)
|
img.Fill(color.Transparent)
|
||||||
eimg, err := theImagesForRestoring.add(img)
|
return theImagesForRestoring.add(img), nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return eimg, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImageFromImage creates a new image with the given image (source).
|
// NewImageFromImage creates a new image with the given image (source).
|
||||||
@ -306,11 +298,7 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eimg, err := theImagesForRestoring.add(img)
|
return theImagesForRestoring.add(img), nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return eimg, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImageWithScreenFramebuffer(width, height int) (*Image, error) {
|
func newImageWithScreenFramebuffer(width, height int) (*Image, error) {
|
||||||
@ -318,9 +306,5 @@ func newImageWithScreenFramebuffer(width, height int) (*Image, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eimg, err := theImagesForRestoring.add(img)
|
return theImagesForRestoring.add(img), nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return eimg, nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user