[Lua Script] Sprite:selection does not work after executing app.command.MoveMask

After moving the selection with the “MoveMask” command, the following three scripts do not work correctly (no error occurs and nothing changes).
However, if I call the “DeselectMask” command, it will work correctly.

I think it’s probably a bug.

  1. Change the selection by calling the Selection:select method.
local sprite = app.activeSprite
local bounds = Rectangle(0, 0, 10, 10)
sprite.selection:select(bounds)

app.command.MoveMask{
    target='content',
    direction='down',
    units='pixel',
    quantity=10,
    wrap=false
  }

-- app.command.DeselectMask{} --Uncommenting this line will make it work as expected

local newBounds = Rectangle(0, 0, 20, 20)
sprite.selection:select(newBounds) -- not working
  1. Call the Selection:deselect method to deselect the selection.
local sprite = app.activeSprite
local bounds = Rectangle(0, 0, 10, 10)
sprite.selection:select(bounds)

app.command.MoveMask{
    target='content',
    direction='down',
    units='pixel',
    quantity=10,
    wrap=false
  }

sprite.selection:deselect() -- not working but app.command.DeselectMask is working
  1. Assign a value to Selection.origin to move the selection.
local sprite = app.activeSprite
local bounds = Rectangle(0, 0, 10, 10)
sprite.selection:select(bounds)

app.command.MoveMask{
    target='content',
    direction='down',
    units='pixel',
    quantity=10,
    wrap=false
  }

-- app.command.DeselectMask{} --Uncommenting this line will make it work as expected
-- sprite.selection:select(bounds)
sprite.selection.origin = Point(0, 0) -- not working

Thanks for reading!

I have just encountered this as well trying to write a script to shuffle some pixels around in 1.3.2 on linux using the installer version.

local spr = app.sprite
if not spr then return end

local sel = spr.selection
if sel.isEmpty then return end

local step = 2

local x = sel.bounds.x
local y = sel.bounds.y
local w = sel.bounds.w
local h = sel.bounds.h

app.transaction(
	"Skew",
	function()
		for i = x, x + w - 1, step do
			spr.selection:select(Rectangle({i, y, step, h}))

			app.command.MoveMask {
				target="content",
				wrap=false,
				direction="up",
				units="pixel",
				quantity=i / step
			}

			-- app.command.DeselectMask()
		end
	end)

Without the deselect mask command Aseprite just moves the first selection and crashes when I do any kind of operation on the sprite afterwards. Sometimes an error pops up just before the crash:

An error has occured.

Details:
Cannot modify the sprite.
It is being used by another command.
Try again.
Cannot modify the sprite when we are undoing/redoing an action.

Internal details:
- Message type: 12
- Editor state: N3app17MovingPixelsStateE

Unless I’m doing something fundamentally wrong I also think it’s a bug.