Don't crash with div by zero when grid bounds has an invalid value

This commit is contained in:
David Capello 2019-05-17 18:11:14 -03:00
parent 54a1b1d67e
commit b0163f3937
2 changed files with 9 additions and 4 deletions

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -21,6 +22,9 @@ gfx::Point snap_to_grid(const gfx::Rect& grid,
const gfx::Point& point,
const PreferSnapTo prefer)
{
if (grid.isEmpty())
return point;
gfx::Point newPoint;
div_t d, dx, dy;

View File

@ -597,10 +597,11 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
if (editor->docPref().show.grid()) {
auto gb = editor->docPref().grid.bounds();
int col = int((std::floor(spritePos.x) - (gb.x % gb.w)) / gb.w);
int row = int((std::floor(spritePos.y) - (gb.y % gb.h)) / gb.h);
sprintf(
buf+std::strlen(buf), " :grid: %d %d", col, row);
if (!gb.isEmpty()) {
int col = int((std::floor(spritePos.x) - (gb.x % gb.w)) / gb.w);
int row = int((std::floor(spritePos.y) - (gb.y % gb.h)) / gb.h);
sprintf(buf+std::strlen(buf), " :grid: %d %d", col, row);
}
}
if (editor->docPref().show.slices()) {