469,320 Members | 2,200 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

unsigned char* compiler error

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.

Nov 1 '06 #1
5 2595
ry********@hotmail.com wrote:
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.
Nov 1 '06 #2
<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.
Nov 1 '06 #3

Jim Langston wrote in message ...
><ry********@hotmail.comwrote 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.
--
Bob R
POVrookie
Nov 1 '06 #4

Jim Langston wrote:
<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.

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

Nov 1 '06 #5

"BobR" <Re***********@worldnet.att.netwrote in message
news:uh*****************@bgtnsc05-news.ops.worldnet.att.net...
>
Jim Langston wrote in message ...
>><ry********@hotmail.comwrote 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
Nov 2 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

96 posts views Thread by John Harrison | last post: by
3 posts views Thread by Sensei | last post: by
10 posts views Thread by Lars Tackmann | last post: by
3 posts views Thread by QQ | last post: by
10 posts views Thread by kar1107 | last post: by
14 posts views Thread by moumita | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.