Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

unhandled exception 'out of memory' when switch to log scale

Hi,
 
my application provides a generic function to switch the scale type of an y-axis from linear to log and vice versa. With certain data (and this is 100% reproducable), the function crashs  with an out of memory exception when it switchs from lin to log. Unfortunately it is not possible to catch the exception, it rather seems to be an unhandled exception caused in a seperate thread. I cannot see that the data in the graph is the reason, because very similar data in other graphs don't show the error. On the other hand, it is reproducible  with same data. Is this a known problem?
 
Best regards,
Andreas
0 Kudos
Message 1 of 11
(5,115 Views)

Can you post a sample project here? I can try to reproduce the problem and see if this is a known issue

Thanks

Bilal Durrani
NI
0 Kudos
Message 2 of 11
(5,110 Views)
Hi Bilal,
 
unfortunately it is a bigger application with a lot of assemblies around and the data is coming from an external file access component.
 
Would it help if I send you the stack trace of the exception? Otherwise I have to extract a small sample project, but this will cost me some time.
 
Thanks for your help!

Andreas
0 Kudos
Message 3 of 11
(5,104 Views)

Hi Bilal,

 

I think I found the reason. If the first value in a 2d Plot array is a negative number (other values are positive), the switching to log. scaletype crashs. But it doesn't crash, if the first value is positive and others are negative. I can send you a sample project if you give me your mail address.

 

I understand that it is a problem to apply a log. scale to negative numbers, but it would already help if I could catch the exception when applying the scale type.

 

Regards

Andreas

 

0 Kudos
Message 4 of 11
(5,094 Views)

Which version of Measurement Studio are you using? You can send me the sample at bilal.durrani at ni.com.

Bilal Durrani
NI
0 Kudos
Message 5 of 11
(5,089 Views)
the version of the UI assembly is 7.1.0.306. I'll send you the sample ASAP.
 
Andreas
0 Kudos
Message 6 of 11
(5,087 Views)
The fact that the order of the -ve number determines whether this error happens is a little weird. But basically, when you take the log of a -ve number, you get a NaN and that is what is causing this overflow. To avoid this, set the ProcessSpecialValue property to true for the plot. Setting this property to true will allow the graph to handle NaN and +/- Infinity values, but it results in a performance hit.

You could handle this yourself as well by going thru your array and changing the -ve numbers to something like 0.001.

We'll  need to investigate the order of the numbers some more. I'll file a report for that.
Bilal Durrani
NI
0 Kudos
Message 7 of 11
(5,078 Views)
modify the data, so that the first value > 0, is not an acceptable solution, because the displayed data is part of a safety relevant test. Setting the "ProcessSpecialValue " property to true is also not a solution if it hits the performance, because there are a lot of waveform graphs, each with about 100000 values and 3 waveform plots.
 
Is there a possibility to change only the first value in the already plotted waveform and change it back after the scaletype has been switched? Or would the latest beta  of the control solve the problem?
 
Thanks for your help.
 
Andreas
0 Kudos
Message 8 of 11
(5,076 Views)

I verified this problem with the MStudio 8.0 for VS 2003 Beta (The beta ended yesterday BTW) and the behavior is the same.

We added the ProcessSpecialValue property for this very purpose because we noticed that GDI+ (the drawing API in the .NET framework) would report errors when drawing NaNs (or other special values). It seems you have hit a special case where if we tell GDI+ to draw a series of points, and if the first point in that series contains NaN, it throws the Overflow exception. If the NaN is anywhere else, it seems to be work itself out. You can see this if you drop a picture box on a form and add the following to its OnPaint method.

        private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            PointF[] points = new PointF[5];
            for(int i =0;i<5;i++)
                points[i] = new PointF(i*20,i*20);

            points[0] = new PointF(40,float.NaN);

            g.DrawLines(Pens.Black,points);
        }

If you change the location of the NaN in the array of PointFs, you will still be able to draw this OK without any exceptions.

This might be one peculiarity. There might be other cases that GDI+ does weird things with special values. I could not find this behavior elaborated in the GDI+ documentation. But in most cases, I would expect it to throw exceptions.

I also noticed that if you enable one of the PointStyles on the plot, you will always get an exception, which makes sense since GDI+ does not know where to draw the NaN on the screen.

ProcessSpecialValues essentially runs through the data and removes any NaNs or other values from the array before passing it on to GDI+. We made this a configurable option since filtering the data everytime would slow things down. This is off by default.

So if you are fairly certain that the only negative value in your data array is in the very first index, changing it would be the easiest alternative. It won't make much sense trying to visualize negative data on a log scale anyway. There really is no good way to modify the data for the graph once it has been passed to the graph. Plus this will allow you to use the PointStyles for the plots and the graph will handle any special cases for you.

I mentioned the performance hit for enabling that property because things are a little slower with that property enabled since we do some additional processing. For you application ( and depending on your system specs) you might not notice the difference. So I would recommend experimenting with that property and see if you notice anything.

Another thing you could try is custom drawing the plot. We allow users to custom draw plots by giving them the array of points and providing BeforeDraw and AfterDraw events. You would get the array and for your custom plot modify the point array. Then draw the plot yourself with GDI+. The help topic "Creating a Custom Plot for the Measurement Studio Scatter and Waveform Graph .NET Controls" mentions how to do this. This is alot more work though.

I hope this explains things.
Bilal Durrani
NI
0 Kudos
Message 9 of 11
(5,066 Views)
I understand the problem with NAN and GDI+. On the other hand, a negative number in a variable of type double is not a NAN and I cannot see why this particular value at the beginning in the array cannot be handled appropriately. However, I use the ProcessSpecialValues property and it seems to run properly now.
 
Thanks for your support again.
 
Andreas
0 Kudos
Message 10 of 11
(5,059 Views)