unsigned char* compiler error

R

ryanlee101

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.
 
M

Mark P

I am getting a exception error when I complie my code.

When you compile it, or when you run it?
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.

Not enough information. Show some code that exhibits the problem.
 
J

Jim Langston

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.
 
B

BobR

Jim Langston wrote in message ...
unsigned char* imageData = NULL;
imageData = new unsigned char[1000];
imageData[0] = 'X';
yada yada. However you want to do it. Remmeber, when you are done with the
memory to free it.

// >free[] imageData;
delete[] imageData;
 
R

Rychi

Jim said:
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.


Thanks for the help I figured it out. I just changed the way I pointed
to ImageData.
 
J

Jim Langston

BobR said:
Jim Langston wrote in message ...
unsigned char* imageData = NULL;
imageData = new unsigned char[1000];
imageData[0] = 'X';
yada yada. However you want to do it. Remmeber, when you are done with
the
memory to free it.

// >free[] imageData;
delete[] imageData;
imageData = NULL; // Some suggest dong this, some don't.

Gah, thanks, I can't believe I did that :D
 

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

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top