Commit fc43e93b authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix a crash when switching subwindows after removing a layer

This happened becayse KisView stored a pointer to a locally active
layer which has been deleted while the view was inactive

BUG:355205
parent 716593ce
......@@ -30,6 +30,7 @@
#include "kis_image_config.h"
#include "kis_debug.h"
#include "kis_node.h"
namespace KritaUtils
......@@ -360,4 +361,18 @@ namespace KritaUtils
return value ? i18n("on") : i18n("off");
}
KisNodeSP nearestNodeAfterRemoval(KisNodeSP node)
{
KisNodeSP newNode = node->nextSibling();
if (!newNode) {
newNode = node->prevSibling();
}
if (!newNode) {
newNode = node->parent();
}
return newNode;
}
}
......@@ -26,8 +26,10 @@ class QPen;
class QPointF;
class QPainterPath;
class QBitArray;
#include <QVector>
#include "kritaimage_export.h"
#include "kis_types.h"
namespace KritaUtils
{
......@@ -64,8 +66,9 @@ namespace KritaUtils
QBitArray KRITAIMAGE_EXPORT mergeChannelFlags(const QBitArray &flags, const QBitArray &parentFlags);
bool KRITAIMAGE_EXPORT compareChannelFlags(QBitArray f1, QBitArray f2);
QString KRITAIMAGE_EXPORT toLocalizedOnOff(bool value);
KisNodeSP KRITAIMAGE_EXPORT nearestNodeAfterRemoval(KisNodeSP node);
}
#endif /* __KRITA_UTILS_H */
......@@ -88,6 +88,7 @@
#include "kis_signal_compressor.h"
#include "kis_filter_manager.h"
#include "krita/gemini/ViewModeSwitchEvent.h"
#include "krita_utils.h"
//static
......@@ -319,6 +320,16 @@ void KisView::setViewManager(KisViewManager *view)
connect(image(), SIGNAL(sigSizeChanged(const QPointF&, const QPointF&)), this, SLOT(slotImageSizeChanged(const QPointF&, const QPointF&)));
connect(image(), SIGNAL(sigResolutionChanged(double,double)), this, SLOT(slotImageResolutionChanged()));
// executed in a context of an image thread
connect(image(), SIGNAL(sigRemoveNodeAsync(KisNodeSP)),
SLOT(slotImageNodeRemoved(KisNodeSP)),
Qt::DirectConnection);
// executed in a context of the gui thread
connect(this, SIGNAL(sigContinueRemoveNode(KisNodeSP)),
SLOT(slotContinueRemoveNode(KisNodeSP)),
Qt::AutoConnection);
/*
* WARNING: Currently we access the global progress bar in two ways:
* connecting to composite progress proxy (strokes) and creating
......@@ -338,6 +349,17 @@ KisViewManager* KisView::viewManager() const
return d->viewManager;
}
void KisView::slotImageNodeRemoved(KisNodeSP node)
{
emit sigContinueRemoveNode(KritaUtils::nearestNodeAfterRemoval(node));
}
void KisView::slotContinueRemoveNode(KisNodeSP newActiveNode)
{
if (!d->isCurrent) {
d->currentNode = newActiveNode;
}
}
QAction *KisView::undoAction() const
{
......
......@@ -219,6 +219,10 @@ public Q_SLOTS:
bool queryClose();
private Q_SLOTS:
void slotImageNodeRemoved(KisNodeSP node);
void slotContinueRemoveNode(KisNodeSP newActiveNode);
Q_SIGNALS:
// From KisImage
void sigSizeChanged(const QPointF &oldStillPoint, const QPointF &newStillPoint);
......@@ -226,6 +230,8 @@ Q_SIGNALS:
void sigColorSpaceChanged(const KoColorSpace* cs);
void titleModified(QString,bool);
void sigContinueRemoveNode(KisNodeSP newActiveNode);
protected:
// QWidget overrides
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment