Bug 87477 - Kst crashes on save if contour plot without colormap exists
Summary: Kst crashes on save if contour plot without colormap exists
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: Compiled Sources Linux
: NOR crash
Target Milestone: ---
Assignee: Rick Chern
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-19 01:53 UTC by Rick Chern
Modified: 2004-08-19 02:24 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rick Chern 2004-08-19 01:53:31 UTC
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.
Comment 1 Rick Chern 2004-08-19 02:24:55 UTC
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;