Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit cc3adcfd authored by Boudewijn Rempt's avatar Boudewijn Rempt

Do not crash on loading broken gradients in layer styles

The real bug is, of course, that we don't load those gradients
correctly to start with.

CCBUG:422320
(cherry picked from commit edf21708d15addb2598a6aedcd510ede14e969f1)
parent c6581b15
......@@ -401,14 +401,13 @@ QDomDocument KisAslLayerStyleSerializer::formXmlDocument() const
w.writeBoolean("enab", outerGlow->effectEnabled());
w.writeEnum("Md ", "BlnM", compositeOpToBlendMode(outerGlow->blendMode()));
if (outerGlow->fillType() == psd_fill_gradient && outerGlow->gradient()) {
KoSegmentGradient *segmentGradient = dynamic_cast<KoSegmentGradient*>(outerGlow->gradient().data());
KoStopGradient *stopGradient = dynamic_cast<KoStopGradient*>(outerGlow->gradient().data());
if (segmentGradient) {
if (segmentGradient && segmentGradient->valid()) {
w.writeSegmentGradient("Grad", segmentGradient);
} else if (stopGradient) {
} else if (stopGradient && stopGradient->valid()) {
w.writeStopGradient("Grad", stopGradient);
} else {
warnKrita << "WARNING: OG: Unknown gradient type!";
......@@ -449,14 +448,13 @@ QDomDocument KisAslLayerStyleSerializer::formXmlDocument() const
w.writeBoolean("enab", innerGlow->effectEnabled());
w.writeEnum("Md ", "BlnM", compositeOpToBlendMode(innerGlow->blendMode()));
if (innerGlow->fillType() == psd_fill_gradient && innerGlow->gradient()) {
KoSegmentGradient *segmentGradient = dynamic_cast<KoSegmentGradient*>(innerGlow->gradient().data());
KoStopGradient *stopGradient = dynamic_cast<KoStopGradient*>(innerGlow->gradient().data());
if (segmentGradient) {
if (segmentGradient && innerGlow->gradient()->valid()) {
w.writeSegmentGradient("Grad", segmentGradient);
} else if (stopGradient) {
} else if (stopGradient && innerGlow->gradient()->valid()) {
w.writeStopGradient("Grad", stopGradient);
} else {
warnKrita << "WARNING: IG: Unknown gradient type!";
......@@ -594,7 +592,7 @@ QDomDocument KisAslLayerStyleSerializer::formXmlDocument() const
KoSegmentGradient *segmentGradient = dynamic_cast<KoSegmentGradient*>(gradientOverlay->gradient().data());
KoStopGradient *stopGradient = dynamic_cast<KoStopGradient*>(gradientOverlay->gradient().data());
if (gradientOverlay->effectEnabled() && (segmentGradient || stopGradient)) {
if (gradientOverlay->effectEnabled() && ((segmentGradient && segmentGradient->valid()) || (stopGradient && stopGradient->valid()))) {
w.enterDescriptor("GrFl", "", "GrFl");
w.writeBoolean("enab", gradientOverlay->effectEnabled());
......@@ -657,13 +655,14 @@ QDomDocument KisAslLayerStyleSerializer::formXmlDocument() const
if (stroke->fillType() == psd_fill_solid_color) {
w.writeColor("Clr ", stroke->color());
} else if (stroke->fillType() == psd_fill_gradient) {
}
else if (stroke->fillType() == psd_fill_gradient) {
KoSegmentGradient *segmentGradient = dynamic_cast<KoSegmentGradient*>(stroke->gradient().data());
KoStopGradient *stopGradient = dynamic_cast<KoStopGradient*>(stroke->gradient().data());
if (segmentGradient) {
if (segmentGradient && segmentGradient->valid()) {
w.writeSegmentGradient("Grad", segmentGradient);
} else if (stopGradient) {
} else if (stopGradient && stopGradient->valid()) {
w.writeStopGradient("Grad", stopGradient);
} else {
warnKrita << "WARNING: Stroke: Unknown gradient type!";
......
......@@ -226,8 +226,6 @@ KoGradientSegment *KoSegmentGradient::segmentAt(qreal t) const
void KoSegmentGradient::colorAt(KoColor& dst, qreal t) const
{
const KoGradientSegment *segment = segmentAt(t);
Q_ASSERT(segment != 0);
if (segment) {
segment->colorAt(dst, t);
}
......
......@@ -359,7 +359,8 @@ void KisAslXmlWriter::writeSegmentGradient(const QString &key, const KoSegmentGr
}
// last segment
{
if (!segments.isEmpty()) {
const KoGradientSegment *lastSeg = segments.last();
QColor color = lastSeg->endColor().toQColor();
......
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