Check that region to patch/copy on "cmd" is not empty to avoid useless cmds

This commit is contained in:
David Capello 2019-04-28 21:26:12 -03:00
parent 23f00d87f6
commit b768d99743
3 changed files with 22 additions and 15 deletions

View File

@ -24,6 +24,8 @@ CopyRegion::CopyRegion(Image* dst, const Image* src,
: WithImage(dst)
, m_alreadyCopied(alreadyCopied)
{
ASSERT(!region.isEmpty());
// Create region to save/swap later
for (const auto& rc : region) {
gfx::Clip clip(

View File

@ -29,6 +29,7 @@ PatchCel::PatchCel(doc::Cel* dstCel,
, m_region(patchedRegion)
, m_pos(patchPos)
{
ASSERT(!patchedRegion.isEmpty());
}
void PatchCel::onExecute()

View File

@ -204,21 +204,25 @@ void ExpandCelCanvas::commit()
regionToPatch = &reduced;
}
if (m_layer->isBackground()) {
m_transaction.execute(
new cmd::CopyRegion(
m_cel->image(),
m_dstImage.get(),
*regionToPatch,
m_bounds.origin()));
}
else {
m_transaction.execute(
new cmd::PatchCel(
m_cel,
m_dstImage.get(),
*regionToPatch,
m_bounds.origin()));
// Check that the region to copy or patch is not empty before we
// create the new cmd
if (!regionToPatch->isEmpty()) {
if (m_layer->isBackground()) {
m_transaction.execute(
new cmd::CopyRegion(
m_cel->image(),
m_dstImage.get(),
*regionToPatch,
m_bounds.origin()));
}
else {
m_transaction.execute(
new cmd::PatchCel(
m_cel,
m_dstImage.get(),
*regionToPatch,
m_bounds.origin()));
}
}
}
else {