aseprite / aseprite

Animated sprite editor & pixel art tool (Windows, macOS, Linux)
https://www.aseprite.org
29.61k stars 6.25k forks source link

cel.image = Image(cel.image, rectangle) can error #4514

Open comods opened 5 months ago

comods commented 5 months ago

cel.image = Image(cel.image, rectangle) can error with [string "internal"]:1: bad argument #2 to 'f' (ImageObj expected, got nil) without any line number nor stack trace.

Image(cel.image, rectangle) can return nil if rectangle is zero width and zero height yet cel.image can't be set to this same nil.

Expected behavior:

Image(cel.image, rectangle) should not return nil but instead Image(1, 1, cel.image.colorMode) otherwise the colorMode is lost.

cel.image = nil should either do:

1: Equivalent of cel.image = Image() which will set image to a 1px by 1px transparent image.

2: Have a sane error message with a line number and stack trace AND update https://www.aseprite.org/api/image#image to say that it can return nil and you must check for it yourself.

Aseprite and System version

Aseprite v1.3.7-x64 appimage

Gasparoken commented 2 weeks ago

@dacap I need your advise: I was thinking about this:

cel.image = nil

An idea: this could result in cel removal. Or as @comods said: give to cel.image a default 1 pixel image with mask color.

In the other hand, I think Image(cel.image, Rectangle(0,0,0,0)) is OK returning nil, perhaps we can add a warning. I'm also fine with giving a default image of 1 pixel.

What do you think about both issues?

dacap commented 2 weeks ago

What do you think about both issues?

I think it should work as you said:

  1. cel.image = nil should remove the cel (and invalidate the cel pointer automatically), and
  2. document that Image(otherImage, rectangle) can return nil if rectangle.isEmpty is true

Other option for 1, but for the future, is to add a special "cel with an empty image". This should be related with #1303.