Commit 3dbe0e80 authored by Sven Langkamp's avatar Sven Langkamp

fix crash on saving an empty image

parent af3ae973
......@@ -433,7 +433,7 @@ vKisNodeSP KisDoc2::activeNodes() const
KisView2 *view = qobject_cast<KisView2*>(v);
if (view) {
KisNodeSP activeNode = view->activeNode();
if (!nodes.contains(activeNode)) {
if (activeNode && !nodes.contains(activeNode)) {
if (activeNode->inherits("KisMask")) {
activeNode = activeNode->parent();
}
......
......@@ -28,6 +28,8 @@
#include <KoDocumentEntry.h>
#include "kis_part2.h"
#include <KoMainWindow.h>
#include <kis_view2.h>
#include "util.h"
void KisDoc2Test::testOpenImageTwiceInSameDoc()
......@@ -47,6 +49,22 @@ void KisDoc2Test::testOpenImageTwiceInSameDoc()
doc.loadNativeFormat(fname2);
}
void KisDoc2Test::testActiveNodes()
{
KisDoc2* doc = createEmptyDocument();
KoMainWindow* shell = new KoMainWindow(doc->documentPart()->componentData());
KisView2* view = new KisView2(static_cast<KisPart2*>(doc->documentPart()), static_cast<KisDoc2*>(doc), shell);
doc->documentPart()->addView(view);
vKisNodeSP nodes = doc->activeNodes();
QVERIFY(nodes.isEmpty());
KisPaintLayerSP paintLayer1 = new KisPaintLayer(doc->image(), "paintlayer1", OPACITY_OPAQUE_U8);
doc->image()->addNode(paintLayer1);
nodes = doc->activeNodes();
QCOMPARE(nodes.count(), 1);
}
QTEST_KDEMAIN(KisDoc2Test, GUI)
#include "kis_doc2_test.moc"
......@@ -27,6 +27,8 @@ class KisDoc2Test : public QObject
private slots:
void testOpenImageTwiceInSameDoc();
void testActiveNodes();
};
#endif /* KIS_DOC2_TEST_H */
......
......@@ -70,5 +70,25 @@ void KisKraSaverTest::testRoundTrip()
QCOMPARE(cv1.count(), cv2.count());
}
void KisKraSaverTest::testSaveEmpty()
{
KisDoc2* doc = createEmptyDocument();
doc->saveNativeFormat("emptytest.kra");
QStringList list;
KisCountVisitor cv1(list, KoProperties());
doc->image()->rootLayer()->accept(cv1);
//delete doc;
KisPart2 part;
KisDoc2 doc2(&part);
part.setDocument(&doc2);
doc2.loadNativeFormat("emptytest.kra");
KisCountVisitor cv2(list, KoProperties());
doc2.image()->rootLayer()->accept(cv2);
QCOMPARE(cv1.count(), cv2.count());
}
QTEST_KDEMAIN(KisKraSaverTest, GUI)
#include "kis_kra_saver_test.moc"
......@@ -29,6 +29,8 @@ private slots:
// XXX: Also test roundtripping of metadata
void testRoundTrip();
void testSaveEmpty();
};
#endif
......@@ -191,7 +191,20 @@ KisDoc2* createCompleteDocument()
return doc;
}
KisDoc2* createEmptyDocument()
{
KisImageWSP image = new KisImage(0, 1024, 1024, KoColorSpaceRegistry::instance()->rgb8(), "test for roundtrip", false);
// FIXME: p will leak here
KisPart2 *p = new KisPart2();
KisDoc2 *doc = new KisDoc2(p);
p->setDocument(doc);
doc->setCurrentImage(image);
doc->documentInfo()->setAboutInfo("title", image->objectName());
return doc;
}
#endif
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