lua: Don't allow negative dimensions in Sprite:resize()

Fixes https://github.com/aseprite/api/issues/5
This commit is contained in:
David Capello 2018-11-24 13:21:35 -03:00
parent 165cd3bdf0
commit 5a340898b1

View File

@ -40,6 +40,8 @@
#include "doc/slice.h"
#include "doc/sprite.h"
#include <algorithm>
namespace app {
namespace script {
@ -84,7 +86,12 @@ int Sprite_eq(lua_State* L)
int Sprite_resize(lua_State* L)
{
auto sprite = get_docobj<Sprite>(L, 1);
const gfx::Size size = convert_args_into_size(L, 2);
gfx::Size size = convert_args_into_size(L, 2);
// Fix invalid sizes
size.w = std::max(1, size.w);
size.h = std::max(1, size.h);
Doc* doc = static_cast<Doc*>(sprite->document());
Tx tx;
DocApi(doc, tx).setSpriteSize(doc->sprite(), size.w, size.h);