PDA

View Full Version : Problem with a QwtPlot with big axes values



agarny
8th March 2013, 13:26
I have a QwtPlot which axes values I set myself based on the values that I need to plot. Now, it may happen that I the axes values are set to +/- DBL_MAX. Now, when replotting (QwtPlot::replot()), updateAxes() is called which, in turn, eventually calls QwtLinearScaleEngine::divideScale() and this is where a problem occurs. Basically, that method will call buildTicks() if stepSize is different from zero, but with my big axes values, stepSize has here a non-finite value. The end result is that the call to buildTicks() never returns and the application eventually crashes.

Now, ideally, QwtLinearScaleEngine::divideScale() would check that stepSize is of a finite value and do something sensible if not. For now, all I personally to avoid the problem is:


if ( qIsFinite ( stepSize ) )
buildTicks( interval, stepSize, maxMinorSteps, ticks );But this means that I don't get any tick at all while, ideally, I would still get some...

Uwe
10th March 2013, 08:47
An infinite step size doesn't happen somehow - you have assigned it explicitly. So this is your code:


if ( !qIsFinite ( stepSize ) )
stepSize = -1;

plot->setAxisScale( ..., stepSize ):It is not the job of Qwt to deal with any type of nonsense the application code does. When passing a double it has to be valid otherwise the result is undefined.

Uwe

agarny
14th March 2013, 15:30
I completely agree with you that "it is not the job of Qwt to deal with any type of nonsense the application code does". However, as far as I can tell, my code provides valid double values. Also, my code doesn't provide any step size to setAxisScale(). It only does something like:


myPlot->setAxisScale(QwtPlot::xBottom, xMin, xMax);
and xMin might be equal to -DBL_MAX and xMax to DBL_MAX (both of which being valid double values indeed). So, in some cases, my call to setAxisScale() might be something like:


myPlot->setAxisScale(QwtPlot::xBottom, -DBL_MAX, DBL_MAX);
and it is in this kind of case that QwtPlot will crash my application, unless I edit the Qwt code as I mentioned in my original message.

Uwe
15th March 2013, 11:07
I'm pretty sure that when using [-DBL_MAX DBL_MAX] you will run into code that does ( max - min ) - the right thing to do is to find these places and to fix them: please file a bug report.

Your workaround might fix a crash but doesn't lead to useful results. Guess a better workaround is to set a reasonable step size manually:


myPlot->setAxisScale(QwtPlot::xBottom, -DBL_MAX, DBL_MAX, stepSize );
But of course this is no solution for zooming panning in combination with a range above DBL_MAX. So the best workaround is to limit the range to something like [-0.5 * DBL_MAX, 0.5 * DBL_MAX ].

Uwe

agarny
18th March 2013, 05:01
My work around was a temporary solution to a crash I was experiencing. As for the code, it does indeed use max-min here and there. I was able to fix a couple of such instances, but then there it the way ticks are computed (i.e. minValue + i * stepSize) which would cause problems, etc. So, in the end, I decided to use your recommended workaround even though [-0.5*DBL_MAX, 0.5*DBL_MAX] still doesn't work for me (but [-0.3*DBL_MAX, 0.3*DBL_MAX] does). No ticks get shown and labels get overlapped. Anyway, as you requested, I am going to file a bug report.

Added after 55 minutes:

Here is the bug report: http://sourceforge.net/p/qwt/bugs/186/.