[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [krita/rempt/impex-refactoring] /: Fix bad weak pointer usage
From:       Frederik Gladhorn <gladhorn () kde ! org>
Date:       2016-11-07 23:45:46
Message-ID: E1c3tbm-0000Dl-Mu () code ! kde ! org
[Download RAW message or body]

Git commit ac2868ad23b50b5e3196eb0d5d1302f5bb02c741 by Frederik Gladhorn.
Committed on 07/11/2016 at 23:42.
Pushed by gladhorn into branch 'rempt/impex-refactoring'.

Fix bad weak pointer usage

The assumption is that weak pointers can become null at any point in
time. Only dereference after converting to a strong pointer.

M  +9    -5    libs/image/brushengine/kis_paintop_settings.cpp
M  +9    -3    libs/image/commands/kis_deselect_global_selection_command.cpp
M  +12   -8    libs/image/commands/kis_image_change_layers_command.cpp
M  +5    -2    libs/image/commands/kis_image_command.cpp
M  +14   -6    libs/image/commands/kis_image_layer_add_command.cpp
M  +15   -8    libs/image/commands/kis_image_layer_move_command.cpp
M  +10   -2    libs/image/commands/kis_image_layer_remove_command.cpp
M  +28   -8    libs/image/commands/kis_image_layer_remove_command_impl.cpp
M  +10   -2    libs/image/commands/kis_image_lock_command.cpp
M  +13   -4    libs/image/commands/kis_image_set_projection_color_space_command.cpp
M  +8    -2    libs/image/commands/kis_node_property_list_command.cpp
M  +11   -3    libs/image/commands/kis_reselect_global_selection_command.cpp
M  +15   -3    libs/image/commands/kis_set_global_selection_command.cpp
M  +12   -4    libs/image/commands_new/kis_change_projection_color_command.cpp
M  +15   -3    libs/image/commands_new/kis_image_resize_command.cpp
M  +18   -4    libs/image/commands_new/kis_image_set_resolution_command.cpp
M  +10   -2    libs/image/kis_clone_layer.cpp
M  +13   -4    libs/image/kis_colorspace_convert_visitor.cpp
M  +27   -6    libs/image/kis_default_bounds.cpp
M  +15   -5    libs/image/kis_group_layer.cc
M  +4    -1    libs/image/kis_histogram.cc
M  +21   -10   libs/image/kis_image_signal_router.cpp
M  +11   -3    libs/image/kis_regenerate_frame_stroke_strategy.cpp
M  +32   -11   libs/image/kis_selection_based_layer.cpp
M  +9    -4    libs/image/kis_suspend_projection_updates_stroke_strategy.cpp
M  +2    -5    plugins/extensions/colorspaceconversion/colorspaceconversion.cc
M  +5    -3    plugins/extensions/imagesize/imagesize.cc
M  +8    -3    plugins/extensions/layergroupswitcher/layergroupswitcher.cpp
M  +16   -14   plugins/extensions/offsetimage/offsetimage.cpp
M  +3    -4    plugins/extensions/separate_channels/kis_channel_separator.cc
M  +1    -1    plugins/extensions/separate_channels/kis_separate_channels_plugin.cc

http://commits.kde.org/krita/ac2868ad23b50b5e3196eb0d5d1302f5bb02c741

diff --git a/libs/image/brushengine/kis_paintop_settings.cpp \
b/libs/image/brushengine/kis_paintop_settings.cpp index b73ba90..8cdb613 100644
--- a/libs/image/brushengine/kis_paintop_settings.cpp
+++ b/libs/image/brushengine/kis_paintop_settings.cpp
@@ -77,11 +77,13 @@ struct Q_DECL_HIDDEN KisPaintOpSettings::Private {
     };
 
     KisPaintopSettingsUpdateProxy* updateProxyNoCreate() const {
-        return preset ? preset->updateProxyNoCreate() : 0;
+        auto presetSP = preset.toStrongRef();
+        return presetSP ? presetSP->updateProxyNoCreate() : 0;
     }
 
     KisPaintopSettingsUpdateProxy* updateProxyCreate() const {
-        return preset ? preset->updateProxy() : 0;
+        auto presetSP = preset.toStrongRef();
+        return presetSP ? presetSP->updateProxy() : 0;
     }
 };
 
@@ -379,9 +381,11 @@ void KisPaintOpSettings::setCanvasMirroring(bool xAxisMirrored, \
bool yAxisMirror  void KisPaintOpSettings::setProperty(const QString & name, const \
QVariant & value)  {
     if (value != KisPropertiesConfiguration::getProperty(name) &&
-            !d->disableDirtyNotifications && this->preset()) {
-
-        this->preset()->setPresetDirty(true);
+            !d->disableDirtyNotifications) {
+        KisPaintOpPresetSP presetSP = preset().toStrongRef();
+        if (presetSP) {
+            presetSP->setPresetDirty(true);
+        }
     }
 
     KisPropertiesConfiguration::setProperty(name, value);
diff --git a/libs/image/commands/kis_deselect_global_selection_command.cpp \
b/libs/image/commands/kis_deselect_global_selection_command.cpp index \
                05c9290..919757c 100644
--- a/libs/image/commands/kis_deselect_global_selection_command.cpp
+++ b/libs/image/commands/kis_deselect_global_selection_command.cpp
@@ -38,11 +38,17 @@ KisDeselectGlobalSelectionCommand::~KisDeselectGlobalSelectionCommand()
  
 void KisDeselectGlobalSelectionCommand::redo()
 {
-    m_oldSelection = m_image->globalSelection();
-    m_image->deselectGlobalSelection();
+    KisImageSP image = m_image.toStrongRef();
+    if (image) {
+        m_oldSelection = image->globalSelection();
+        image->deselectGlobalSelection();
+    }
 }
 
 void KisDeselectGlobalSelectionCommand::undo()
 {
-    m_image->setGlobalSelection(m_oldSelection);
+    KisImageSP image = m_image.toStrongRef();
+    if (image) {
+        image->setGlobalSelection(m_oldSelection);
+    }
 }
diff --git a/libs/image/commands/kis_image_change_layers_command.cpp \
b/libs/image/commands/kis_image_change_layers_command.cpp index 9649f2c..7fe87ee \
                100644
--- a/libs/image/commands/kis_image_change_layers_command.cpp
+++ b/libs/image/commands/kis_image_change_layers_command.cpp
@@ -33,16 +33,20 @@ KisImageChangeLayersCommand::KisImageChangeLayersCommand(KisImageWSP \
image, KisN  
 void KisImageChangeLayersCommand::redo()
 {
-    m_image->setRootLayer(static_cast<KisGroupLayer*>(m_newRootLayer.data()));
-
-    m_image->refreshGraphAsync();
-    m_image->notifyLayersChanged();
+    KisImageSP image = m_image.toStrongRef();
+    if (image) {
+        image->setRootLayer(static_cast<KisGroupLayer*>(m_newRootLayer.data()));
+        image->refreshGraphAsync();
+        image->notifyLayersChanged();
+    }
 }
 
 void KisImageChangeLayersCommand::undo()
 {
-    m_image->setRootLayer(static_cast<KisGroupLayer*>(m_oldRootLayer.data()));
-
-    m_image->refreshGraphAsync();
-    m_image->notifyLayersChanged();
+    KisImageSP image = m_image.toStrongRef();
+    if (image) {
+        image->setRootLayer(static_cast<KisGroupLayer*>(m_oldRootLayer.data()));
+        image->refreshGraphAsync();
+        image->notifyLayersChanged();
+    }
 }
diff --git a/libs/image/commands/kis_image_command.cpp \
b/libs/image/commands/kis_image_command.cpp index 8bccab5..f0679bc 100644
--- a/libs/image/commands/kis_image_command.cpp
+++ b/libs/image/commands/kis_image_command.cpp
@@ -75,7 +75,10 @@ void KisImageCommand::UpdateTarget::update() {
     if (node) {
         node->setDirty(m_updateRect);
     } else {
-        m_image->refreshGraphAsync(m_removedNodeParent);
-        m_removedNodeParent->setDirty(m_updateRect);
+        KisImageSP image = m_image.toStrongRef();
+        if (image) {
+            image->refreshGraphAsync(m_removedNodeParent);
+            m_removedNodeParent->setDirty(m_updateRect);
+        }
     }
 }
diff --git a/libs/image/commands/kis_image_layer_add_command.cpp \
b/libs/image/commands/kis_image_layer_add_command.cpp index e92280f..95a1443 100644
--- a/libs/image/commands/kis_image_layer_add_command.cpp
+++ b/libs/image/commands/kis_image_layer_add_command.cpp
@@ -57,24 +57,32 @@ KisImageLayerAddCommand::KisImageLayerAddCommand(KisImageWSP \
image,  
 void KisImageLayerAddCommand::redo()
 {
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
     if (m_aboveThis || m_index == quint32(-1)) {
-        m_image->addNode(m_layer, m_parent, m_aboveThis);
+        image->addNode(m_layer, m_parent, m_aboveThis);
     } else {
-        m_image->addNode(m_layer, m_parent, m_index);
+        image->addNode(m_layer, m_parent, m_index);
     }
 
     if (m_doRedoUpdates) {
-        m_layer->setDirty(m_image->bounds());
+        m_layer->setDirty(image->bounds());
     }
 }
 
 void KisImageLayerAddCommand::undo()
 {
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
     if (m_doUndoUpdates) {
-        UpdateTarget target(m_image, m_layer, m_image->bounds());
-        m_image->removeNode(m_layer);
+        UpdateTarget target(image, m_layer, image->bounds());
+        image->removeNode(m_layer);
         target.update();
     } else {
-        m_image->removeNode(m_layer);
+        image->removeNode(m_layer);
     }
 }
diff --git a/libs/image/commands/kis_image_layer_move_command.cpp \
b/libs/image/commands/kis_image_layer_move_command.cpp index 23f0635..be6d55c 100644
--- a/libs/image/commands/kis_image_layer_move_command.cpp
+++ b/libs/image/commands/kis_image_layer_move_command.cpp
@@ -61,29 +61,36 @@ KisImageLayerMoveCommand::KisImageLayerMoveCommand(KisImageWSP \
image, KisNodeSP  
 void KisImageLayerMoveCommand::redo()
 {
-
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
     if (m_useIndex) {
-        m_image->moveNode(m_layer, m_newParent, m_index);
+        image->moveNode(m_layer, m_newParent, m_index);
     } else {
-        m_image->moveNode(m_layer, m_newParent, m_newAbove);
+        image->moveNode(m_layer, m_newParent, m_newAbove);
     }
 
     if (m_doUpdates) {
-        m_image->refreshGraphAsync(m_prevParent);
+        image->refreshGraphAsync(m_prevParent);
         if (m_newParent != m_prevParent) {
-            m_layer->setDirty(m_image->bounds());
+            m_layer->setDirty(image->bounds());
         }
     }
 }
 
 void KisImageLayerMoveCommand::undo()
 {
-    m_image->moveNode(m_layer, m_prevParent, m_prevAbove);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->moveNode(m_layer, m_prevParent, m_prevAbove);
 
     if (m_doUpdates) {
-        m_image->refreshGraphAsync(m_newParent);
+        image->refreshGraphAsync(m_newParent);
         if (m_newParent != m_prevParent) {
-            m_layer->setDirty(m_image->bounds());
+            m_layer->setDirty(image->bounds());
         }
     }
 }
diff --git a/libs/image/commands/kis_image_layer_remove_command.cpp \
b/libs/image/commands/kis_image_layer_remove_command.cpp index 8e62748..6217e1f \
                100644
--- a/libs/image/commands/kis_image_layer_remove_command.cpp
+++ b/libs/image/commands/kis_image_layer_remove_command.cpp
@@ -58,7 +58,11 @@ void KisImageLayerRemoveCommand::addSubtree(KisImageWSP image, \
KisNodeSP node)  
 void KisImageLayerRemoveCommand::redo()
 {
-    UpdateTarget target(m_image, m_node, m_image->bounds());
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    UpdateTarget target(image, m_node, image->bounds());
     KisImageCommand::redo();
 
     if (m_doRedoUpdates) {
@@ -75,6 +79,10 @@ void KisImageLayerRemoveCommand::undo()
          * We are removing the group recursively, so the updates should
          * come recursively as well
          */
-        m_image->refreshGraphAsync(m_node, m_image->bounds());
+        KisImageSP image = m_image.toStrongRef();
+        if (!image) {
+            return;
+        }
+        image->refreshGraphAsync(m_node, image->bounds());
     }
 }
diff --git a/libs/image/commands/kis_image_layer_remove_command_impl.cpp \
b/libs/image/commands/kis_image_layer_remove_command_impl.cpp index bdbce86..124afa8 \
                100644
--- a/libs/image/commands/kis_image_layer_remove_command_impl.cpp
+++ b/libs/image/commands/kis_image_layer_remove_command_impl.cpp
@@ -59,28 +59,39 @@ KisImageLayerRemoveCommandImpl::~KisImageLayerRemoveCommandImpl()
 
 void KisImageLayerRemoveCommandImpl::redo()
 {
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
     m_d->processClones(m_d->node);
-    m_image->removeNode(m_d->node);
+    image->removeNode(m_d->node);
 }
 
 void KisImageLayerRemoveCommandImpl::undo()
 {
-    m_image->addNode(m_d->node, m_d->prevParent, m_d->prevAbove);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->addNode(m_d->node, m_d->prevParent, m_d->prevAbove);
     m_d->restoreClones();
 }
 
 void KisImageLayerRemoveCommandImpl::Private::restoreClones()
 {
     Q_ASSERT(reincarnatedNodes.size() == clonesList.size());
-
+    KisImageSP image = q->m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
     for (int i = 0; i < reincarnatedNodes.size(); i++) {
         KisCloneLayerSP clone = clonesList[i];
         KisLayerSP newNode = reincarnatedNodes[i];
 
-        q->m_image->addNode(clone, newNode->parent(), newNode);
+        image->addNode(clone, newNode->parent(), newNode);
         moveChildren(newNode, clone);
         moveClones(newNode, clone);
-        q->m_image->removeNode(newNode);
+        image->removeNode(newNode);
     }
 }
 
@@ -102,6 +113,11 @@ void \
KisImageLayerRemoveCommandImpl::Private::processClones(KisNodeSP node)  }
     }
 
+    KisImageSP image = q->m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+
     /**
      * Move the children and transitive clones to the
      * reincarnated nodes
@@ -110,18 +126,22 @@ void \
KisImageLayerRemoveCommandImpl::Private::processClones(KisNodeSP node)  \
KisCloneLayerSP clone = clonesList[i];  KisLayerSP newNode = reincarnatedNodes[i];
 
-        q->m_image->addNode(newNode, clone->parent(), clone);
+        image->addNode(newNode, clone->parent(), clone);
         moveChildren(clone, newNode);
         moveClones(clone, newNode);
-        q->m_image->removeNode(clone);
+        image->removeNode(clone);
     }
 }
 
 void KisImageLayerRemoveCommandImpl::Private::moveChildren(KisNodeSP src, KisNodeSP \
dst)  {
+    KisImageSP image = q->m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
     KisNodeSP child = src->firstChild();
     while(child) {
-        q->m_image->moveNode(child, dst, dst->lastChild());
+        image->moveNode(child, dst, dst->lastChild());
         child = child->nextSibling();
     }
 }
diff --git a/libs/image/commands/kis_image_lock_command.cpp \
b/libs/image/commands/kis_image_lock_command.cpp index 7a6bc52..c743aeb 100644
--- a/libs/image/commands/kis_image_lock_command.cpp
+++ b/libs/image/commands/kis_image_lock_command.cpp
@@ -31,11 +31,19 @@ KisImageLockCommand::KisImageLockCommand(KisImageWSP image, bool \
lockImage)  
 void KisImageLockCommand::redo()
 {
-    m_image->refreshGraph();
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->refreshGraph();
 }
 
 void KisImageLockCommand::undo()
 {
-    m_image->refreshGraph();
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->refreshGraph();
 }
 
diff --git a/libs/image/commands/kis_image_set_projection_color_space_command.cpp \
b/libs/image/commands/kis_image_set_projection_color_space_command.cpp index \
                fbf2922..e4d2a32 100644
--- a/libs/image/commands/kis_image_set_projection_color_space_command.cpp
+++ b/libs/image/commands/kis_image_set_projection_color_space_command.cpp
@@ -28,16 +28,25 @@
 KisImageSetProjectionColorSpaceCommand::KisImageSetProjectionColorSpaceCommand(KisImageWSP \
image, const KoColorSpace * afterColorSpace)  : KisImageCommand(kundo2_i18n("Convert \
Image Type"), image)  {
-    m_beforeColorSpace = image->colorSpace();
-    m_afterColorSpace = afterColorSpace;
+    KisImageSP imageSP = image.toStrongRef();
+    if (imageSP) {
+        m_beforeColorSpace = imageSP->colorSpace();
+        m_afterColorSpace = afterColorSpace;
+    }
 }
 
 void KisImageSetProjectionColorSpaceCommand::redo()
 {
-    m_image->setProjectionColorSpace(m_afterColorSpace);
+    KisImageSP image = m_image.toStrongRef();
+    if (image) {
+        image->setProjectionColorSpace(m_afterColorSpace);
+    }
 }
 
 void KisImageSetProjectionColorSpaceCommand::undo()
 {
-    m_image->setProjectionColorSpace(m_beforeColorSpace);
+    KisImageSP image = m_image.toStrongRef();
+    if (image) {
+        image->setProjectionColorSpace(m_beforeColorSpace);
+    }
 }
diff --git a/libs/image/commands/kis_node_property_list_command.cpp \
b/libs/image/commands/kis_node_property_list_command.cpp index fe87e2b..070df07 \
                100644
--- a/libs/image/commands/kis_node_property_list_command.cpp
+++ b/libs/image/commands/kis_node_property_list_command.cpp
@@ -71,10 +71,16 @@ void KisNodePropertyListCommand::doUpdate(const \
KisBaseNode::PropertyList &oldPr  
     if (oldPassThroughValue && !newPassThroughValue) {
         KisLayerSP layer(qobject_cast<KisLayer*>(m_node.data()));
-        layer->image()->refreshGraphAsync(layer);
+        KisImageSP image = layer->image().toStrongRef();
+        if (image) {
+            image->refreshGraphAsync(layer);
+        }
     } else if (m_node->parent() && !oldPassThroughValue && newPassThroughValue) {
         KisLayerSP layer(qobject_cast<KisLayer*>(m_node->parent().data()));
-        layer->image()->refreshGraphAsync(layer);
+        KisImageSP image = layer->image().toStrongRef();
+        if (image) {
+            image->refreshGraphAsync(layer);
+        }
     } else {
         m_node->setDirty(); // TODO check if visibility was changed or not
     }
diff --git a/libs/image/commands/kis_reselect_global_selection_command.cpp \
b/libs/image/commands/kis_reselect_global_selection_command.cpp index \
                c38dc26..9012c38 100644
--- a/libs/image/commands/kis_reselect_global_selection_command.cpp
+++ b/libs/image/commands/kis_reselect_global_selection_command.cpp
@@ -38,17 +38,25 @@ KisReselectGlobalSelectionCommand::~KisReselectGlobalSelectionCommand()
  
 void KisReselectGlobalSelectionCommand::redo()
 {
-    m_canReselect = m_image->canReselectGlobalSelection();
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    m_canReselect = image->canReselectGlobalSelection();
 
     if (m_canReselect) {
-        m_image->reselectGlobalSelection();
+        image->reselectGlobalSelection();
     }
 }
 
 void KisReselectGlobalSelectionCommand::undo()
 {
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
     if (m_canReselect) {
-        m_image->deselectGlobalSelection();
+        image->deselectGlobalSelection();
     }
 }
 
diff --git a/libs/image/commands/kis_set_global_selection_command.cpp \
b/libs/image/commands/kis_set_global_selection_command.cpp index d01b0cd..681c317 \
                100644
--- a/libs/image/commands/kis_set_global_selection_command.cpp
+++ b/libs/image/commands/kis_set_global_selection_command.cpp
@@ -29,18 +29,30 @@
 KisSetGlobalSelectionCommand::KisSetGlobalSelectionCommand(KisImageWSP image, \
KisSelectionSP selection)  : m_image(image)
 {
-    m_oldSelection = m_image->globalSelection();
+    KisImageSP imageSP = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    m_oldSelection = imageSP->globalSelection();
     m_newSelection = selection;
 }
 
 void KisSetGlobalSelectionCommand::redo()
 {
-    m_image->setGlobalSelection(m_newSelection);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setGlobalSelection(m_newSelection);
 }
 
 void KisSetGlobalSelectionCommand::undo()
 {
-    m_image->setGlobalSelection(m_oldSelection);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setGlobalSelection(m_oldSelection);
 }
 
 KisSetEmptyGlobalSelectionCommand::KisSetEmptyGlobalSelectionCommand(KisImageWSP \
                image)
diff --git a/libs/image/commands_new/kis_change_projection_color_command.cpp \
b/libs/image/commands_new/kis_change_projection_color_command.cpp index \
                9e0d433..5d4c0d8 100644
--- a/libs/image/commands_new/kis_change_projection_color_command.cpp
+++ b/libs/image/commands_new/kis_change_projection_color_command.cpp
@@ -59,12 +59,20 @@ bool KisChangeProjectionColorCommand::mergeWith(const \
KUndo2Command* command)  
 void KisChangeProjectionColorCommand::redo()
 {
-    m_image->setDefaultProjectionColor(m_newColor);
-    m_image->animationInterface()->setDefaultProjectionColor(m_newColor);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setDefaultProjectionColor(m_newColor);
+    image->animationInterface()->setDefaultProjectionColor(m_newColor);
 }
 
 void KisChangeProjectionColorCommand::undo()
 {
-    m_image->setDefaultProjectionColor(m_oldColor);
-    m_image->animationInterface()->setDefaultProjectionColor(m_oldColor);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setDefaultProjectionColor(m_oldColor);
+    image->animationInterface()->setDefaultProjectionColor(m_oldColor);
 }
diff --git a/libs/image/commands_new/kis_image_resize_command.cpp \
b/libs/image/commands_new/kis_image_resize_command.cpp index d7971f5..86f5350 100644
--- a/libs/image/commands_new/kis_image_resize_command.cpp
+++ b/libs/image/commands_new/kis_image_resize_command.cpp
@@ -29,16 +29,28 @@ KisImageResizeCommand::KisImageResizeCommand(KisImageWSP image,
       m_image(image)
 {
     // do we really need a translatable name for the command?
-    m_sizeBefore = image->size();
+    KisImageSP imageSP = m_image.toStrongRef();
+    if (!imageSP) {
+        return;
+    }
+    m_sizeBefore = imageSP->size();
     m_sizeAfter = newSize;
 }
 
 void KisImageResizeCommand::redo()
 {
-    m_image->setSize(m_sizeAfter);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setSize(m_sizeAfter);
 }
 
 void KisImageResizeCommand::undo()
 {
-    m_image->setSize(m_sizeBefore);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setSize(m_sizeBefore);
 }
diff --git a/libs/image/commands_new/kis_image_set_resolution_command.cpp \
b/libs/image/commands_new/kis_image_set_resolution_command.cpp index 2a8a9fc..4136ceb \
                100644
--- a/libs/image/commands_new/kis_image_set_resolution_command.cpp
+++ b/libs/image/commands_new/kis_image_set_resolution_command.cpp
@@ -27,19 +27,33 @@ KisImageSetResolutionCommand::KisImageSetResolutionCommand(KisImageWSP \
image, qr  , m_image(image)
     , m_newXRes(newXRes)
     , m_newYRes(newYRes)
-    , m_oldXRes(m_image->xRes())
-    , m_oldYRes(m_image->yRes())
+    , m_oldXRes(0)
+    , m_oldYRes(0)
 {
+    KisImageSP imageSP = image.toStrongRef();
+     if (!imageSP) {
+         return;
+     }
+     m_oldXRes = imageSP->xRes();
+     m_oldYRes = imageSP->yRes();
 }
 
 void KisImageSetResolutionCommand::undo()
 {
-    m_image->setResolution(m_oldXRes, m_oldYRes);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setResolution(m_oldXRes, m_oldYRes);
 }
 
 void KisImageSetResolutionCommand::redo()
 {
-    m_image->setResolution(m_newXRes, m_newYRes);
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+    image->setResolution(m_newXRes, m_newYRes);
 }
 
 
diff --git a/libs/image/kis_clone_layer.cpp b/libs/image/kis_clone_layer.cpp
index 54172ea..c3def95e 100644
--- a/libs/image/kis_clone_layer.cpp
+++ b/libs/image/kis_clone_layer.cpp
@@ -59,7 +59,11 @@ KisCloneLayer::KisCloneLayer(KisLayerSP from, KisImageWSP image, \
const QString &  : KisLayer(image, name, opacity)
         , m_d(new Private(new KisDefaultBounds(image)))
 {
-    m_d->fallback = new KisPaintDevice(image->colorSpace());
+    KisImageSP imageSP = image.toStrongRef();
+    if (!imageSP) {
+        return;
+    }
+    m_d->fallback = new KisPaintDevice(imageSP->colorSpace());
     m_d->copyFrom = from;
     m_d->type = COPY_PROJECTION;
 
@@ -164,7 +168,11 @@ void KisCloneLayer::setDirtyOriginal(const QRect &rect)
 
 void KisCloneLayer::notifyParentVisibilityChanged(bool value)
 {
-    KisLayer::setDirty(image()->bounds());
+    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        return;
+    }
+    KisLayer::setDirty(imageSP->bounds());
     KisLayer::notifyParentVisibilityChanged(value);
 }
 
diff --git a/libs/image/kis_colorspace_convert_visitor.cpp \
b/libs/image/kis_colorspace_convert_visitor.cpp index 36e323d..40dca99 100644
--- a/libs/image/kis_colorspace_convert_visitor.cpp
+++ b/libs/image/kis_colorspace_convert_visitor.cpp
@@ -112,24 +112,29 @@ bool KisColorSpaceConvertVisitor::convertPaintDevice(KisLayer* \
layer)  }
     }
 
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return false;
+    }
+
     if (layer->original()) {
         KUndo2Command* cmd = layer->original()->convertTo(m_dstColorSpace, \
m_renderingIntent, m_conversionFlags);  if (cmd) {
-            m_image->undoAdapter()->addCommand(cmd);
+            image->undoAdapter()->addCommand(cmd);
         }
     }
 
     if (layer->paintDevice()) {
         KUndo2Command* cmd = layer->paintDevice()->convertTo(m_dstColorSpace, \
m_renderingIntent, m_conversionFlags);  if (cmd) {
-            m_image->undoAdapter()->addCommand(cmd);
+            image->undoAdapter()->addCommand(cmd);
         }
     }
 
     if (layer->projection()) {
         KUndo2Command* cmd = layer->projection()->convertTo(m_dstColorSpace, \
m_renderingIntent, m_conversionFlags);  if (cmd) {
-            m_image->undoAdapter()->addCommand(cmd);
+            image->undoAdapter()->addCommand(cmd);
         }
     }
 
@@ -146,9 +151,13 @@ bool KisColorSpaceConvertVisitor::convertPaintDevice(KisLayer* \
layer)  
 bool KisColorSpaceConvertVisitor::visit(KisColorizeMask *mask)
 {
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return false;
+    }
     KUndo2Command* cmd = mask->setColorSpace(m_dstColorSpace, m_renderingIntent, \
m_conversionFlags);  if (cmd) {
-        m_image->undoAdapter()->addCommand(cmd);
+        image->undoAdapter()->addCommand(cmd);
     }
     return true;
 }
diff --git a/libs/image/kis_default_bounds.cpp b/libs/image/kis_default_bounds.cpp
index 98b849b..42028d9 100644
--- a/libs/image/kis_default_bounds.cpp
+++ b/libs/image/kis_default_bounds.cpp
@@ -55,28 +55,48 @@ QRect KisDefaultBounds::bounds() const
     /**
      * By default return infinite rect to cover everything
      */
-    return m_d->image ? m_d->image->effectiveLodBounds() : infiniteRect;
+    KisImageSP image = m_d->image.toStrongRef();
+    if (!image) {
+        return infiniteRect;
+    }
+    return image->effectiveLodBounds();
 }
 
 bool KisDefaultBounds::wrapAroundMode() const
 {
-    return m_d->image ? m_d->image->wrapAroundModeActive() : false;
+    KisImageSP image = m_d->image.toStrongRef();
+    if (!image) {
+        return false;
+    }
+    return image->wrapAroundModeActive();
 }
 
 int KisDefaultBounds::currentLevelOfDetail() const
 {
-    return m_d->image ? m_d->image->currentLevelOfDetail() : 0;
+    KisImageSP image = m_d->image.toStrongRef();
+    if (!image) {
+        return 0;
+    }
+    return image->currentLevelOfDetail();
 }
 
 int KisDefaultBounds::currentTime() const
 {
-    KisImageAnimationInterface *interface = m_d->image ? \
m_d->image->animationInterface() : 0; +    KisImageSP image = \
m_d->image.toStrongRef(); +    if (!image) {
+        return 0;
+    }
+    KisImageAnimationInterface *interface = image->animationInterface();
     return interface ? interface->currentTime() : 0;
 }
 
 bool KisDefaultBounds::externalFrameActive() const
 {
-    KisImageAnimationInterface *interface = m_d->image ? \
m_d->image->animationInterface() : 0; +    KisImageSP image = \
m_d->image.toStrongRef(); +    if (!image) {
+        return 0;
+    }
+    KisImageAnimationInterface *interface = image->animationInterface();
     return interface ? interface->externalFrameActive() : false;
 }
 
@@ -103,7 +123,8 @@ KisSelectionDefaultBounds::~KisSelectionDefaultBounds()
 
 QRect KisSelectionDefaultBounds::bounds() const
 {
-    QRect additionalRect = m_d->parentDevice ? m_d->parentDevice->extent() : \
QRect(); +    auto parentDevice = m_d->parentDevice.toStrongRef();
+    QRect additionalRect = parentDevice ? parentDevice->extent() : QRect();
     return additionalRect | KisDefaultBounds::bounds();
 }
 
diff --git a/libs/image/kis_group_layer.cc b/libs/image/kis_group_layer.cc
index 3567ade..4480b88 100644
--- a/libs/image/kis_group_layer.cc
+++ b/libs/image/kis_group_layer.cc
@@ -144,8 +144,13 @@ void KisGroupLayer::setImage(KisImageWSP image)
 
 KisLayerSP KisGroupLayer::createMergedLayerTemplate(KisLayerSP prevLayer)
 {
-    KisGroupLayer *prevGroup = dynamic_cast<KisGroupLayer*>(prevLayer.data());
+    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        warnImage << "image invalid";
+        return KisLayerSP();
+    }
 
+    KisGroupLayer *prevGroup = dynamic_cast<KisGroupLayer*>(prevLayer.data());
     if (prevGroup && canMergeAndKeepBlendOptions(prevLayer)) {
         KisSharedPtr<KisGroupLayer> merged(new KisGroupLayer(*prevGroup));
 
@@ -153,14 +158,15 @@ KisLayerSP KisGroupLayer::createMergedLayerTemplate(KisLayerSP \
prevLayer)  
         for (child = firstChild(); child; child = child->nextSibling()) {
             cloned = child->clone();
-            image()->addNode(cloned, merged);
+            imageSP->addNode(cloned, merged);
         }
 
-        image()->refreshGraphAsync(merged);
+        imageSP->refreshGraphAsync(merged);
 
         return merged;
-    } else
+    } else {
         return KisLayer::createMergedLayerTemplate(prevLayer);
+    }
 }
 
 void KisGroupLayer::fillMergedLayerTemplate(KisLayerSP dstLayer, KisLayerSP \
prevLayer) @@ -172,8 +178,12 @@ void \
KisGroupLayer::fillMergedLayerTemplate(KisLayerSP dstLayer, KisLayerSP prev  
 void KisGroupLayer::resetCache(const KoColorSpace *colorSpace)
 {
+    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        return;
+    }
     if (!colorSpace)
-        colorSpace = image()->colorSpace();
+        colorSpace = imageSP->colorSpace();
 
     Q_ASSERT(colorSpace);
 
diff --git a/libs/image/kis_histogram.cc b/libs/image/kis_histogram.cc
index 787f112..3e6dbcd 100644
--- a/libs/image/kis_histogram.cc
+++ b/libs/image/kis_histogram.cc
@@ -35,7 +35,10 @@ KisHistogram::KisHistogram(const KisPaintLayerSP layer,
 {
     Q_ASSERT(producer);
 
-    m_bounds = layer->image()->bounds();
+    KisImageSP imageSP = layer->image().toStrongRef();
+    if (imageSP) {
+        m_bounds = imageSP->bounds();
+    }
     m_type = type;
     m_producer = producer;
     m_selection = false;
diff --git a/libs/image/kis_image_signal_router.cpp \
b/libs/image/kis_image_signal_router.cpp index 4f44093..b2a857a 100644
--- a/libs/image/kis_image_signal_router.cpp
+++ b/libs/image/kis_image_signal_router.cpp
@@ -89,7 +89,10 @@ void KisImageSignalRouter::emitNodeHasBeenAdded(KisNode *parent, \
int index)  KisNodeSP newNode = parent->at(index);
 
     if (!newNode->inherits("KisSelectionMask")) {
-        m_image->invalidateAllFrames();
+        KisImageSP image = m_image.toStrongRef();
+        if (image) {
+            image->invalidateAllFrames();
+        }
     }
 
     emit sigNodeAddedAsync(newNode);
@@ -100,7 +103,10 @@ void KisImageSignalRouter::emitAboutToRemoveANode(KisNode \
*parent, int index)  KisNodeSP removedNode = parent->at(index);
 
     if (!removedNode->inherits("KisSelectionMask")) {
-        m_image->invalidateAllFrames();
+        KisImageSP image = m_image.toStrongRef();
+        if (image) {
+            image->invalidateAllFrames();
+        }
     }
 
     emit sigRemoveNodeAsync(removedNode);
@@ -109,30 +115,35 @@ void KisImageSignalRouter::emitAboutToRemoveANode(KisNode \
*parent, int index)  
 void KisImageSignalRouter::slotNotification(KisImageSignalType type)
 {
+    KisImageSP image = m_image.toStrongRef();
+    if (!image) {
+        return;
+    }
+
     switch(type.id) {
     case LayersChangedSignal:
-        m_image->invalidateAllFrames();
+        image->invalidateAllFrames();
         emit sigLayersChangedAsync();
         break;
     case ModifiedSignal:
         emit sigImageModified();
         break;
     case SizeChangedSignal:
-        m_image->invalidateAllFrames();
+        image->invalidateAllFrames();
         emit sigSizeChanged(type.sizeChangedSignal.oldStillPoint,
                             type.sizeChangedSignal.newStillPoint);
         break;
     case ProfileChangedSignal:
-        m_image->invalidateAllFrames();
-        emit sigProfileChanged(m_image->profile());
+        image->invalidateAllFrames();
+        emit sigProfileChanged(image->profile());
         break;
     case ColorSpaceChangedSignal:
-        m_image->invalidateAllFrames();
-        emit sigColorSpaceChanged(m_image->colorSpace());
+        image->invalidateAllFrames();
+        emit sigColorSpaceChanged(image->colorSpace());
         break;
     case ResolutionChangedSignal:
-        m_image->invalidateAllFrames();
-        emit sigResolutionChanged(m_image->xRes(), m_image->yRes());
+        image->invalidateAllFrames();
+        emit sigResolutionChanged(image->xRes(), image->yRes());
         break;
     case NodeReselectionRequestSignal:
         if (type.nodeReselectionSignal.newActiveNode ||
diff --git a/libs/image/kis_regenerate_frame_stroke_strategy.cpp \
b/libs/image/kis_regenerate_frame_stroke_strategy.cpp index 329e76a..b0d1929 100644
--- a/libs/image/kis_regenerate_frame_stroke_strategy.cpp
+++ b/libs/image/kis_regenerate_frame_stroke_strategy.cpp
@@ -57,12 +57,20 @@ struct KisRegenerateFrameStrokeStrategy::Private
     };
 
     void saveAndResetUpdatesFilter() {
-        prevUpdatesFilter = interface->image()->projectionUpdatesFilter();
-        interface->image()->setProjectionUpdatesFilter(KisProjectionUpdatesFilterSP());
 +        KisImageSP image = interface->image().toStrongRef();
+        if (!image) {
+            return;
+        }
+        prevUpdatesFilter = image->projectionUpdatesFilter();
+        image->setProjectionUpdatesFilter(KisProjectionUpdatesFilterSP());
     }
 
     void restoreUpdatesFilter() {
-        interface->image()->setProjectionUpdatesFilter(prevUpdatesFilter);
+        KisImageSP image = interface->image().toStrongRef();
+        if (!image) {
+            return;
+        }
+        image->setProjectionUpdatesFilter(prevUpdatesFilter);
         prevUpdatesFilter.clear();
     }
 };
diff --git a/libs/image/kis_selection_based_layer.cpp \
b/libs/image/kis_selection_based_layer.cpp index 623eb7b..09daf22 100644
--- a/libs/image/kis_selection_based_layer.cpp
+++ b/libs/image/kis_selection_based_layer.cpp
@@ -62,9 +62,12 @@ KisSelectionBasedLayer::KisSelectionBasedLayer(KisImageWSP image,
         initSelection();
     else
         setInternalSelection(selection);
-
-    m_d->paintDevice = KisPaintDeviceSP(new KisPaintDevice(this, \
                image->colorSpace(), KisDefaultBoundsSP(new \
                KisDefaultBounds(image))));
-    connect(image.data(), SIGNAL(sigSizeChanged(QPointF,QPointF)), \
SLOT(slotImageSizeChanged())); +    KisImageSP imageSP = image.toStrongRef();
+    if (!imageSP) {
+        return;
+    }
+    m_d->paintDevice = KisPaintDeviceSP(new KisPaintDevice(this, \
imageSP->colorSpace(), KisDefaultBoundsSP(new KisDefaultBounds(image)))); +    \
connect(imageSP.data(), SIGNAL(sigSizeChanged(QPointF,QPointF)), \
SLOT(slotImageSizeChanged()));  }
 
 KisSelectionBasedLayer::KisSelectionBasedLayer(const KisSelectionBasedLayer& rhs)
@@ -191,8 +194,12 @@ QRect KisSelectionBasedLayer::needRect(const QRect &rect, \
PositionToFilthy pos)  
 void KisSelectionBasedLayer::resetCache(const KoColorSpace *colorSpace)
 {
+    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        return;
+    }
     if (!colorSpace)
-        colorSpace = image()->colorSpace();
+        colorSpace = imageSP->colorSpace();
 
     if (!m_d->paintDevice ||
             *m_d->paintDevice->colorSpace() != *colorSpace) {
@@ -218,11 +225,15 @@ void \
KisSelectionBasedLayer::setInternalSelection(KisSelectionSP selection)  \
m_d->selection = 0;  }
 
-    if (selection->pixelSelection()->defaultBounds()->bounds() != image()->bounds()) \
{ +    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        return;
+    }
+    if (selection->pixelSelection()->defaultBounds()->bounds() != imageSP->bounds()) \
                {
         qWarning() << "WARNING: KisSelectionBasedLayer::setInternalSelection"
                    << "New selection has suspicious default bounds";
         qWarning() << "WARNING:" << \
                ppVar(selection->pixelSelection()->defaultBounds()->bounds());
-        qWarning() << "WARNING:" << ppVar(image()->bounds());
+        qWarning() << "WARNING:" << ppVar(imageSP->bounds());
     }
 }
 
@@ -269,24 +280,34 @@ KisKeyframeChannel \
*KisSelectionBasedLayer::requestKeyframeChannel(const QString  void \
KisSelectionBasedLayer::setDirty()  {
     Q_ASSERT(image());
-
-    setDirty(image()->bounds());
+    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        return;
+    }
+    setDirty(imageSP->bounds());
 }
 
 QRect KisSelectionBasedLayer::extent() const
 {
     Q_ASSERT(image());
-
+    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        return QRect();
+    }
     return m_d->selection ?
-           m_d->selection->selectedRect() : image()->bounds();
+           m_d->selection->selectedRect() : imageSP->bounds();
 }
 
 QRect KisSelectionBasedLayer::exactBounds() const
 {
     Q_ASSERT(image());
+    KisImageSP imageSP = image().toStrongRef();
+    if (!imageSP) {
+        return QRect();
+    }
 
     return m_d->selection ?
-           m_d->selection->selectedExactRect() : image()->bounds();
+           m_d->selection->selectedExactRect() : imageSP->bounds();
 }
 
 QImage KisSelectionBasedLayer::createThumbnail(qint32 w, qint32 h)
diff --git a/libs/image/kis_suspend_projection_updates_stroke_strategy.cpp \
b/libs/image/kis_suspend_projection_updates_stroke_strategy.cpp index \
                0a944d4..94f7034 100644
--- a/libs/image/kis_suspend_projection_updates_stroke_strategy.cpp
+++ b/libs/image/kis_suspend_projection_updates_stroke_strategy.cpp
@@ -211,16 +211,21 @@ void \
                KisSuspendProjectionUpdatesStrokeStrategy::doStrokeCallback(KisStrokeJobDat
                
     Private::UpdatesBarrierData *barrierData = \
                dynamic_cast<Private::UpdatesBarrierData*>(data);
     Private::IssueCanvasUpdatesData *canvasUpdates = \
dynamic_cast<Private::IssueCanvasUpdatesData*>(data);  
+    KisImageSP image = m_d->image.toStrongRef();
+    if (!image) {
+        return;
+    }
+
     if (suspendData) {
-        m_d->image->setProjectionUpdatesFilter(
+        image->setProjectionUpdatesFilter(
             KisProjectionUpdatesFilterSP(new Private::SuspendLod0Updates()));
     } else if (resumeData) {
-        m_d->image->disableUIUpdates();
+        image->disableUIUpdates();
         resumeAndIssueUpdates(false);
     } else if (barrierData) {
-        m_d->image->enableUIUpdates();
+        image->enableUIUpdates();
     } else if (canvasUpdates) {
-        m_d->image->notifyProjectionUpdated(canvasUpdates->updateRect);
+        image->notifyProjectionUpdated(canvasUpdates->updateRect);
     }
 }
 
diff --git a/plugins/extensions/colorspaceconversion/colorspaceconversion.cc \
b/plugins/extensions/colorspaceconversion/colorspaceconversion.cc index \
                81367b8..dcfd109 100644
--- a/plugins/extensions/colorspaceconversion/colorspaceconversion.cc
+++ b/plugins/extensions/colorspaceconversion/colorspaceconversion.cc
@@ -68,11 +68,9 @@ ColorSpaceConversion::~ColorSpaceConversion()
 
 void ColorSpaceConversion::slotImageColorSpaceConversion()
 {
-    KisImageWSP image = m_view->image();
-
+    KisImageSP image = m_view->image().toStrongRef();
     if (!image) return;
 
-
     DlgColorSpaceConversion * dlgColorSpaceConversion = new \
DlgColorSpaceConversion(m_view->mainWindow(), "ColorSpaceConversion");  bool \
                allowLCMSOptimization = KisConfig().allowLCMSOptimization();
     dlgColorSpaceConversion->m_page->chkAllowLCMSOptimization->setChecked(allowLCMSOptimization);
 @@ -98,8 +96,7 @@ void ColorSpaceConversion::slotImageColorSpaceConversion()
 
 void ColorSpaceConversion::slotLayerColorSpaceConversion()
 {
-
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image().toStrongRef();
     if (!image) return;
 
     KisLayerSP layer = m_view->activeLayer();
diff --git a/plugins/extensions/imagesize/imagesize.cc \
b/plugins/extensions/imagesize/imagesize.cc index 3734ee6..ca21339 100644
--- a/plugins/extensions/imagesize/imagesize.cc
+++ b/plugins/extensions/imagesize/imagesize.cc
@@ -67,8 +67,7 @@ ImageSize::~ImageSize()
 
 void ImageSize::slotImageSize()
 {
-    KisImageWSP image = m_view->image();
-
+    KisImageSP image = m_view->image().toStrongRef();
     if (!image) return;
 
     DlgImageSize * dlgImageSize = new DlgImageSize(m_view->mainWindow(), \
image->width(), image->height(), image->yRes()); @@ -133,7 +132,10 @@ void \
ImageSize::slotLayerSize()  
 void ImageSize::slotSelectionScale()
 {
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image();
+    if (!image) {
+        return;
+    }
     KisLayerSP layer = m_view->activeLayer();
 
     KIS_ASSERT_RECOVER_RETURN(image && layer);
diff --git a/plugins/extensions/layergroupswitcher/layergroupswitcher.cpp \
b/plugins/extensions/layergroupswitcher/layergroupswitcher.cpp index 7b988fa..6a31698 \
                100644
--- a/plugins/extensions/layergroupswitcher/layergroupswitcher.cpp
+++ b/plugins/extensions/layergroupswitcher/layergroupswitcher.cpp
@@ -47,7 +47,6 @@ LayerGroupSwitcher::LayerGroupSwitcher(QObject *parent, const \
QVariantList &)  action = new KisAction(i18n("Move into next group"), this);
     addAction("LayerGroupSwitcher/next", action);
     connect(action, SIGNAL(triggered()), this, SLOT(moveIntoNextGroup()));
-
 }
 
 LayerGroupSwitcher::~LayerGroupSwitcher()
@@ -56,7 +55,10 @@ LayerGroupSwitcher::~LayerGroupSwitcher()
 
 void LayerGroupSwitcher::moveIntoNextGroup()
 {
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image().toStrongRef();
+    if (!image) {
+        return;
+    }
     KisNodeManager *nodeManager = m_view->nodeManager();
     KisLayerSP active = nodeManager->activeLayer();
     if (!active) {
@@ -94,7 +96,10 @@ void LayerGroupSwitcher::moveIntoNextGroup()
 
 void LayerGroupSwitcher::moveIntoPreviousGroup()
 {
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image().toStrongRef();
+    if (!image) {
+        return;
+    }
     KisNodeManager *nodeManager = m_view->nodeManager();
     KisLayerSP active = nodeManager->activeLayer();
     if (!active) {
diff --git a/plugins/extensions/offsetimage/offsetimage.cpp \
b/plugins/extensions/offsetimage/offsetimage.cpp index c62d5fa..8bc975b 100644
--- a/plugins/extensions/offsetimage/offsetimage.cpp
+++ b/plugins/extensions/offsetimage/offsetimage.cpp
@@ -59,7 +59,7 @@ OffsetImage::~OffsetImage()
 
 void OffsetImage::slotOffsetImage()
 {
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image().toStrongRef();
     if (image) {
 
         DlgOffsetImage * dlgOffsetImage = new DlgOffsetImage(m_view->mainWindow(), \
"OffsetImage", offsetWrapRect().size()); @@ -83,22 +83,21 @@ void \
OffsetImage::slotOffsetImage()  
 void OffsetImage::slotOffsetLayer()
 {
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image().toStrongRef();
     if (image) {
 
-    DlgOffsetImage * dlgOffsetImage = new DlgOffsetImage(m_view->mainWindow(), \
                "OffsetLayer", offsetWrapRect().size());
-    Q_CHECK_PTR(dlgOffsetImage);
-
-    KUndo2MagicString actionName = kundo2_i18n("Offset Layer");
-    dlgOffsetImage->setCaption(i18nc("@title:window", "Offset Layer"));
+        DlgOffsetImage * dlgOffsetImage = new DlgOffsetImage(m_view->mainWindow(), \
"OffsetLayer", offsetWrapRect().size()); +        Q_CHECK_PTR(dlgOffsetImage);
 
-    if (dlgOffsetImage->exec() == QDialog::Accepted) {
-        QPoint offsetPoint = QPoint(dlgOffsetImage->offsetX(), \
                dlgOffsetImage->offsetY());
-        KisNodeSP activeNode = m_view->activeNode();
-        offsetImpl(actionName, activeNode, offsetPoint);
-    }
-    delete dlgOffsetImage;
+        KUndo2MagicString actionName = kundo2_i18n("Offset Layer");
+        dlgOffsetImage->setCaption(i18nc("@title:window", "Offset Layer"));
 
+        if (dlgOffsetImage->exec() == QDialog::Accepted) {
+            QPoint offsetPoint = QPoint(dlgOffsetImage->offsetX(), \
dlgOffsetImage->offsetY()); +            KisNodeSP activeNode = m_view->activeNode();
+            offsetImpl(actionName, activeNode, offsetPoint);
+        }
+        delete dlgOffsetImage;
     }
     else
     {
@@ -131,7 +130,10 @@ QRect OffsetImage::offsetWrapRect()
     }
     else
     {
-        offsetWrapRect = m_view->image()->bounds();
+        KisImageSP image = m_view->image().toStrongRef();
+        if (image) {
+            offsetWrapRect = image->bounds();
+        }
     }
     return offsetWrapRect;
 }
diff --git a/plugins/extensions/separate_channels/kis_channel_separator.cc \
b/plugins/extensions/separate_channels/kis_channel_separator.cc index \
                436286e..0748064 100644
--- a/plugins/extensions/separate_channels/kis_channel_separator.cc
+++ b/plugins/extensions/separate_channels/kis_channel_separator.cc
@@ -66,7 +66,7 @@ KisChannelSeparator::KisChannelSeparator(KisViewManager * view)
 
 void KisChannelSeparator::separate(KoUpdater * progressUpdater, enumSepAlphaOptions \
alphaOps, enumSepSource sourceOps, enumSepOutput outputOps, bool downscale, bool \
toColor)  {
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image();
     if (!image) return;
 
     KisPaintDeviceSP src;
@@ -100,7 +100,7 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, \
enumSepAlphaOpti  
     QRect rect = src->exactBounds();
 
-    m_view->image()->lock();
+    image->lock();
     int i = 0;
     for (QList<KoChannelInfo *>::const_iterator it = begin; it != end; ++it) {
 
@@ -267,8 +267,7 @@ void KisChannelSeparator::separate(KoUpdater * progressUpdater, \
enumSepAlphaOpti  if (outputOps == TO_LAYERS) {
             undo->endMacro();
         }
-        m_view->image()->unlock();
+        image->unlock();
         image->setModified();
     }
-
 }
diff --git a/plugins/extensions/separate_channels/kis_separate_channels_plugin.cc \
b/plugins/extensions/separate_channels/kis_separate_channels_plugin.cc index \
                16713b2..e09d46b 100644
--- a/plugins/extensions/separate_channels/kis_separate_channels_plugin.cc
+++ b/plugins/extensions/separate_channels/kis_separate_channels_plugin.cc
@@ -58,7 +58,7 @@ KisSeparateChannelsPlugin::~KisSeparateChannelsPlugin()
 
 void KisSeparateChannelsPlugin::slotSeparate()
 {
-    KisImageWSP image = m_view->image();
+    KisImageSP image = m_view->image();
     if (!image) return;
 
     KisLayerSP l = m_view->nodeManager()->activeLayer();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic