<ry********@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>I am getting a exception error when I complie my code.
The error is:
- imageData 0x00000000 <Bad Ptr>
type unsigned char *
I think it is from when I declare some of my char variables
unsigned char *imageData; // the map image data
unsigned char *landTexture; // land texture data
unsigned char *waterTexture; // water texture data
I have tried changing the data type but I just get cannot convert
errors. Any help would be appreciated.
That is a null pointer error. I doubt you are getting an error when you
compile your code, but when you run it, since that is a run time error.
Basically, it means that your pointer isn't pointing to anything. Most
likely you are running in debug mode which was nice enough to initialize the
variable to NULL for you, but in run time it wouldn't, then it would be a
different type of memory error.
unsigned char *imageData = NULL;
Now try to do something wiht imageData and you'll get a memory error,
because it's not pointing to anything. Okay, you have a pointer to unsigned
char. What do you want to do with it? Do you want to point it to an
already allocated buffer of image data? Or do you want to allocate memory
to hold image data?
The pointer itself is just something that will point to unsigned char data.
But you still have to tell it to point there.
I.E.
unsigned char* imageData = NULL;
imageData = new unsigned char[1000];
Now imeageData points to a block of 1000 unsigned chars that were allocated
using new. The memory is uninitialized and can, and will, contain anything.
You ned to set the data to something using the pointer.
imageData[0] = 'X';
yada yada. However you want to do it. Remmeber, when you are done with the
memory to free it.
free[] imageData;
imageData = NULL; // Some suggest dong this, some don't.
Another way, is to make your unsigned char ponter point to some buffer
somewhere.
unsigned char* imageData = NULL;
imageData = &SomeBuffer;
now imageData will point to the location that SomeBuffer is stored (which
needs to be unsigned char without a cast).
Since you didn't use new to allocate the data, don't use free to release it
(not for imageData anyway).
Incidently, most of this code can be put on one line.
unsigned char* imageData = new unsigned char[1000];
unsigned char* imageData = &SomeBuffer;
It seems that you are creating a pointer and are not sure what to do with
it, I think you need to study up on pointers a bit more.