Bug 144099 - Kst freezes when plotting data
Summary: Kst freezes when plotting data
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-11 23:02 UTC by Andrew Walker
Modified: 2007-04-12 19:59 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Data set (530 bytes, text/plain)
2007-04-11 23:02 UTC, Andrew Walker
Details
Proposed patch (2.74 KB, patch)
2007-04-12 00:57 UTC, Andrew Walker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Walker 2007-04-11 23:02:06 UTC
Version:           1.4.0 (using KDE KDE 3.5.1)
Installed from:    Compiled From Sources
OS:                Linux

PROBLEM:

Start Kst
Start the data wizard and select the attached data source
Select all vectors for plotting
Select 'All curves in one plot'
Click Finish

RESULTS:

Kst freezes

EXPECTED RESULTS:

Kst plots data
Comment 1 Andrew Walker 2007-04-11 23:02:33 UTC
Created attachment 20242 [details]
Data set
Comment 2 Andrew Walker 2007-04-12 00:57:28 UTC
Created attachment 20243 [details]
Proposed patch

Prevent an infinite loop in KstColorSequence::next( )
Comment 3 Adam Treat 2007-04-12 17:51:37 UTC
The patch works, but why do you insist upon putting all local variable declarations at the top of the method?  Why not declare 'start' where you initialize it?
Comment 4 Andrew Walker 2007-04-12 19:59:13 UTC
SVN commit 653140 by arwalker:

BUG:144099 prevent infinite loop in color sequence

 M  +21 -21    kstcolorsequence.cpp  


--- branches/work/kst/1.5/kst/src/libkstmath/kstcolorsequence.cpp #653139:653140
@@ -95,16 +95,12 @@
   // check we are not already using this color, but if
   //  we are then count the number of usages of each color
   //  in the palette.
+  if (_self->_ptr >= _self->_count * 2) {
+    _self->_ptr = 0;
+  }
   start = _self->_ptr;
-  if (start >= _self->_count * 2) {
-    start = 0;
-  }
 
-  while (_self->_ptr != start) {
-    if (_self->_ptr >= _self->_count * 2) {
-      _self->_ptr = 0;
-    }
-
+  do {
     dark_factor = 100 + ( 50 * ( _self->_ptr / _self->_count ) );
     color = _self->_pal->color( _self->_ptr % _self->_count).dark(dark_factor);
 
@@ -125,23 +121,26 @@
     }
 
     _self->_ptr++;
-  }
+    if (_self->_ptr >= _self->_count * 2) {
+      _self->_ptr = 0;
+    }
+  } while (_self->_ptr != start);
 
   // if we are already using this color then use the least used color for all the curves.
   if (usage[_self->_ptr] != 0) {
+    _self->_ptr = start;
     ptrMin = _self->_ptr;
 
-    while (_self->_ptr != start) {
-      if (_self->_ptr >= _self->_count * 2) {
-        _self->_ptr = 0;
-      }
-
+    do {
       if (usage[_self->_ptr] < usage[ptrMin]) {
         ptrMin = _self->_ptr;
       }
 
       _self->_ptr++;
-    }
+      if (_self->_ptr >= _self->_count * 2) {
+        _self->_ptr = 0;
+      }
+    } while (_self->_ptr != start);
 
     _self->_ptr = ptrMin;
   }
@@ -171,30 +170,31 @@
 QColor KstColorSequence::next(const QColor& badColor) {
   QColor color;
   int dark_factor;
+  int start;
 
   if (!_self) {
     sdColorSequence.setObject(_self, new KstColorSequence);
   }
   _self->createPalette();
 
-  int start = _self->_ptr;
+  if (_self->_ptr >= _self->_count * 2) {
+    _self->_ptr = 0;
+  }
+  start = _self->_ptr;
 
   // find the next color in the sequence that it not too close to the bad color.
   if (badColor.isValid()) {
     do {
+      dark_factor = 100 + ( 50 * ( _self->_ptr / _self->_count ) );
+      color = _self->_pal->color( _self->_ptr++ % _self->_count).dark(dark_factor);
       if (_self->_ptr >= _self->_count * 2) {
         _self->_ptr = 0;
       }
-      dark_factor = 100 + ( 50 * ( _self->_ptr / _self->_count ) );
-      color = _self->_pal->color( _self->_ptr++ % _self->_count).dark(dark_factor);
     } while (colorsTooClose(color, badColor) && start != _self->_ptr);
   }
 
   // if we couldn't find one then just use the next color in the sequence.
   if (start == _self->_ptr) {
-    if (_self->_ptr >= _self->_count * 2) {
-      _self->_ptr = 0;
-    }
     dark_factor = 100 + ( 50 * ( _self->_ptr / _self->_count ) );
     color = _self->_pal->color( _self->_ptr++ % _self->_count).dark(dark_factor);
   }