Discussion:
Weird crash at second DrawLine
(too old to reply)
Sonnich Jensen
2016-07-07 10:50:40 UTC
Permalink
Hi all

I have a weird problem - in 10-15% of the time this line crashes, when drawing axis on a graph - the y axis goes well, but the X axis fails at app every 10th
time.

Right now it works with dummy data, which are always within certain limist.

Can anyone suggest why this goes wrong?

Only the second time it fails, the first line never fails.

WBR
Sonnich



// draw axises
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, margin), new Point(marginLeft, bmp.Height - margin));

int ypos = margin + (int)Math.Round((yMax) * ystep);
if (yMax >= 0 && yMin <= 0)
{
// crashes here
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, ypos), new Point(bmp.Width - margin, ypos));
}
Arne Vajhøj
2016-07-07 21:22:25 UTC
Permalink
Post by Sonnich Jensen
I have a weird problem - in 10-15% of the time this line crashes, when drawing axis on a graph - the y axis goes well, but the X axis fails at app every 10th
time.
Right now it works with dummy data, which are always within certain limist.
Can anyone suggest why this goes wrong?
Only the second time it fails, the first line never fails.
// draw axises
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, margin), new Point(marginLeft, bmp.Height - margin));
int ypos = margin + (int)Math.Round((yMax) * ystep);
if (yMax >= 0 && yMin <= 0)
{
// crashes here
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, ypos), new Point(bmp.Width - margin, ypos));
}
What exception do you get?

Is it a multi-threaded application?

Arne
lin shi hao
2016-07-10 12:55:25 UTC
Permalink
bmp.Width < margin ?
Post by Sonnich Jensen
Hi all
I have a weird problem - in 10-15% of the time this line crashes, when
drawing axis on a graph - the y axis goes well, but the X axis fails at
app every 10th
time.
Right now it works with dummy data, which are always within certain limist.
Can anyone suggest why this goes wrong?
Only the second time it fails, the first line never fails.
WBR
Sonnich
// draw axises
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, margin),
new Point(marginLeft, bmp.Height - margin));
int ypos = margin + (int)Math.Round((yMax) * ystep);
if (yMax >= 0 && yMin <= 0)
{
// crashes here
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, ypos),
new Point(bmp.Width - margin, ypos));
}
--- news://freenews.netfront.net/ - complaints: ***@netfront.net ---
Sonnich Jensen
2016-07-12 13:19:57 UTC
Permalink
Post by Sonnich Jensen
Hi all
I have a weird problem - in 10-15% of the time this line crashes, when drawing axis on a graph - the y axis goes well, but the X axis fails at app every 10th
time.
Right now it works with dummy data, which are always within certain limist.
Can anyone suggest why this goes wrong?
Only the second time it fails, the first line never fails.
WBR
Sonnich
// draw axises
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, margin), new Point(marginLeft, bmp.Height - margin));
int ypos = margin + (int)Math.Round((yMax) * ystep);
if (yMax >= 0 && yMin <= 0)
{
// crashes here
bmpGraphics.DrawLine(new Pen(Color.Black), new Point(marginLeft, ypos), new Point(bmp.Width - margin, ypos));
}
Ot was a mathematical problem, ypos = 1/0, the division by 0 was possible under certain very specific situations.

It gave an Overflow error, or just hang in this situation.

Loading...