By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

unsigned char* compiler error

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
<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

P: n/a

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

P: n/a

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

P: n/a

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