thePixel
is an unsigned int but passed in as unsigned long. The function might be overflowing your integer and changing y
. Try declaring thePixel
as unsigned long
In memory, the variables are just laid out one after another. The function getPixel:at:y:
assumes it has 64 bits to write to in the input, because it takes an unsigned long *
. However your own variable thePixel
is an unsigned int *
and writing an unsigned long
to it will cause an overflow in memory