Version: 1.0.0_devel (using KDE KDE 3.2.1) Installed from: Compiled From Sources OS: Linux How to reproduce: - start kst - create an image with a contour plot, but without a colormap. Do not change from a colormap/both to a contour map. - make sure the image is not later changed to a colormap/both and back - try to save the file Kst crashes. Expected behaviour Kst does not crash.
CVS commit by rchern: When saving, don't try to get the name from a null palette pointer. Also log a debug message when the palette cannot be found when loading, and don't bother creating a default palette if no colormap exists. CCMAIL: 87477-done@bugs.kde.org M +18 -9 kstimage.cpp 1.16 --- kdeextragear-2/kst/kst/kstimage.cpp #1.15:1.16 @@ -27,4 +27,6 @@ #include <math.h> +#include <qmessagebox.h> + KstImage::KstImage(QDomElement& e) : KstDataObject(e){ QString in_tag, in_matrixName, in_paletteName; @@ -63,11 +65,4 @@ KstImage::KstImage(QDomElement& e) : Kst } _inputMatrixLoadQueue.append(qMakePair(QString("THEMATRIX"), in_matrixName)); - KPalette *in_pal = new KPalette(in_paletteName); - //maybe the palette doesn't exist anymore. Generate a grayscale palette then. - if (in_pal->nrColors() <= 0) { - for (int i = 0; i < 256; i++) { - _pal->addColor(QColor(i,i,i)); - } - } setTagName(in_tag); @@ -77,5 +72,17 @@ KstImage::KstImage(QDomElement& e) : Kst _zLower = in_zLower; _zUpper = in_zUpper; + + if (_hasColorMap) { + KPalette *in_pal = new KPalette(in_paletteName); + //maybe the palette doesn't exist anymore. Generate a grayscale palette then. + if (in_pal->nrColors() <= 0) { + for (int i = 0; i < 256; i++) { + in_pal->addColor(QColor(i,i,i)); + } + KstDebug::self()->log(i18n("Unable to find palette %1. Using a 256 color grayscale palette instead.").arg(in_paletteName), + KstDebug::Warning); + } _pal = in_pal; + } if (!_hasColorMap) { @@ -175,5 +182,7 @@ void KstImage::save(QTextStream &ts) { ts << " <matrixtag>" << _matrix->tagName() << "</matrixtag>" << endl; ts << " <hascolormap>" << _hasColorMap << "</hascolormap>" <<endl; + if (_pal) { ts << " <palettename>" << _pal->name() << "</palettename>" << endl; + } ts << " <lowerthreshold>" << _zLower << "</lowerthreshold>" << endl; ts << " <upperthreshold>" << _zUpper << "</upperthreshold>" << endl;