odd pointer dereference problem 
Author Message
 odd pointer dereference problem

Hi all--

I'm having a really odd pointer dereference problem.  I'm
using a pointer to traverse a bitmap for performance
reasons.  I'm using code that I found here:

http://www.*-*-*.com/
url=/library/en-us/dncscol/html/CSharp11152001.asp

Everything is working fine, most of the time.  The bitmap
is being locked, etc., the pointers are working correct
and I get the results I expect.  

However, there's one particular time when dereferencing a
pointer to pass to a function that I get a "Object
reference not set to an instance of an object"
exception.  It doesn't happen for every pixel in the
bitmap, just the very last one.  Here's a code sample:

---------------
HSI[,] hsi = new HSI[bitmap.Width, bitmap.Height];
Point size = bitmap.PixelSize;
Pixel* pPixel;
bitmap.LockBitmap();
for (int j = 0; j < size.Y; j++)
{
   pPixel = bitmap.PixelAt(0, j);
   for (int i = 0; i < size.X; i++, pPixel++)
   {
      hsi[i,j].Set(*pPixel);  // <----- problem
   }

Quote:
}

bitmap.UnlockBitmap();
-----------------

At the line marked 'problem' I get the aforementioned
exception on the last pixel of the image.  If I change
that one line to:

Pixel p = *pPixel;
hsi[i,j].Set(p);

It works fine...no exception thrown.  

Has anyone seen this or have any ideas why I can always
do the pointer dereference as the function call
argument?  I'm assuming the bitmap is created correctly
as all I'm doing is calling the GDI+ constructor (and the
fact that the above code replacement works).

Thanks,
jason



Tue, 29 Mar 2005 11:26:41 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Can't dereference pointer to pointer?

2. dereference a pointer to a variable

3. dereference of a zero pointer

4. Dereference void pointer help, xxgdb help please

5. ODD __gc problem

6. Very odd string problem

7. Odd ADSI Problem

8. Odd Setup Problems

9. Odd problem with System.Collections.SortedList

10. Odd scanf problem

11. Problem with odd loop when passing float to function

12. Problem with odd loop when passing float to function

 

 
Powered by phpBB® Forum Software