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) : WithImage(dst)
, m_alreadyCopied(alreadyCopied) , m_alreadyCopied(alreadyCopied)
{ {
ASSERT(!region.isEmpty());
// Create region to save/swap later // Create region to save/swap later
for (const auto& rc : region) { for (const auto& rc : region) {
gfx::Clip clip( gfx::Clip clip(

View File

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

View File

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