# \[Script\] Crashes with selection:deselect() and Undo (Ctrl+Z)

**URL:** https://community.aseprite.org/t/script-crashes-with-selection-deselect-and-undo-ctrl-z/6169
**Category:** Bug Reports
**Created:** [June 17, 2020, 12:22pm UTC](https://community.aseprite.org/t/script-crashes-with-selection-deselect-and-undo-ctrl-z/6169 "2020-06-17T12:22:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![msk-k](https://community.aseprite.org/letter_avatar/msk-k/32/5_5575768a8748004e209b776fc1b2916d.png) [@msk-k](https://community.aseprite.org/u/msk-k)
#### Post date: [June 17, 2020, 12:22pm UTC](https://community.aseprite.org/t/script-crashes-with-selection-deselect-and-undo-ctrl-z/6169/1 "2020-06-17T12:22:07Z")

</div>

## Version Infomation

Aseprite v1.2.20  
Surface 6 pro/Windows 10 1903

### Reproduction procedure

1. Execute lua method “app.activeSprite.selection:deselect()” **with nothing selected**.
2. Then Undo (Ctrl+Z) and Aseprite throws an exception and crashes.  
(Nothing should have been changed, but Undo will be made.)

### Appendix

[appendix 1.]

The methods that raised the exception as follows.

```auto
aseprite/src/doc/mask.cpp
void Mask::copyFrom(const Mask* sourceMask)
line 120

```

The exception that occurred are as follows.

```auto
Exception has occurred: W32/0xc0000005
Exception thrown: read access violation.
sourceMask was nullptr.

```

I actually debugged it and found that the value of sourceMask was nullptr.

[appendix 2.]

When using the “app.command.DeselectMask()” .  
no exceptions are raised under the same conditions.  
Because nothing has been changed, I can’t Undo.

=================================

Is this a specification?  
If so, you might want to include the following information as a supplementary item in documentation.  
“Do not execute app.activeSprite.selection:deselect() with nothing selected.”

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [June 17, 2020, 8:15pm UTC](https://community.aseprite.org/t/script-crashes-with-selection-deselect-and-undo-ctrl-z/6169/2 "2020-06-17T20:15:21Z")

</div>

Hi @msk-k, thanks for reporting this bug, there will be fixed in the next release (maybe today).

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [June 17, 2020, 11:32pm UTC](https://community.aseprite.org/t/script-crashes-with-selection-deselect-and-undo-ctrl-z/6169/3 "2020-06-17T23:32:15Z")

</div>

Fixed in [Aseprite v1.2.21](https://community.aseprite.org/t/aseprite-v1-2-21/6178)

---

<div class="post-metadata">

### Author: ![dacap](https://community.aseprite.org/user_avatar/community.aseprite.org/dacap/32/10_2.png) [@dacap](https://community.aseprite.org/u/dacap)
#### Post date: [June 17, 2020, 11:32pm UTC](https://community.aseprite.org/t/script-crashes-with-selection-deselect-and-undo-ctrl-z/6169/4 "2020-06-17T23:32:22Z")

</div>


