[BugReport] Bitmap.SetPixel()

L

Lloyd Dupont

it seems that if we set a pixel outside Bitmap bounds there is a crash of
the application ...
 
M

Mark Johnson

This sounds more like an ArrayOutofRange Error.

Checking beforehand would avoid this,

if (((x > m_Bitmap.Width ) || (y > m_Bitmap.Height)) || ((x < 0) || (y <
0)))
{
MessageBox.Show("Out of Range Error");
}
else
{
try
{
m_Bitmap.SetPixel(x,y,Color.Black);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
} // else if

without checking, should tell you more and avoid a crash.

Mark Johnson, Berlin Germany
(e-mail address removed)
 
L

Lloyd Dupont

tss....
of course if I test there is no problem.

However what that maybe not stated clearly in my mail is:

- there is no exception thrown
- the application crash.

do you see the difference ?
something unacceptable for a .NET application !
 
M

Mark Johnson

Can you stop the Program in the Debugger to check the values being used
before this happens?
Does this allways happen or only on certin (unknown) conditions?
Are you doing this in a loop or are the values of x,y being set somewere
outside?
 
L

Lloyd Dupont

ho...
in fact I had a small Paint program embeded in my application.
but when I took off the required file and make a standalone paint program
the code just throw an exception as expected, instead of crashing.

mmhh.. sorry.. puzzled.. and worried that there might be a pointer
corruption somewhere in my big app..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top