473,626 Members | 3,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2838
ry********@hotm ail.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********@hot mail.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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********@ho tmail.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********@hot mail.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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.ne twrote in message
news:uh******** *********@bgtns c05-news.ops.worldn et.att.net...
>
Jim Langston wrote in message ...
>><ry********@h otmail.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

96
3946
by: John Harrison | last post by:
I knew that unsigned integral data types were the cause of scads of mostly spurious warning messages, but I didn't realise that they were a security risk too (see here http://www.securitytracker.com/alerts/2004/Feb/1009067.html). All for one measly extra bit. So has the time come for C++ to deprecate unsigned integral types? john
3
2948
by: Sensei | last post by:
Hi. I have a problem with a C++ code I can't resolve, or better, I can't see what the problem should be! Here's an excerpt of the incriminated code: === bspalgo.cpp // THAT'S THE BAD FUNCTION!!
10
14402
by: Lars Tackmann | last post by:
Does the c standard state that for all c99 implementation char as standard is equal unsigned char ??? - or do i have to take this into account when writing my program ???.
3
41925
by: QQ | last post by:
Hello, Here is my simple program int main() { unsigned char a =0x81; char b = 0x81; printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b); printf("cast char to unsigned 0x%x\n",(unsigned char)b); }
10
23592
by: kar1107 | last post by:
Hi all, Can the compiler chose the type of an enum to be signed or unsigned int? I thought it must be int; looks like it changes based on the assigned values. Below if I don't initialize FOO_STORE to be, say -10, I get a warning about unsigned comparison and I'm seeing an infinite loop. If I do initialize FOO_STORE = -10, I don't see any warnings. No infinite loop.
6
5630
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. char temp; std::vector<unsigned charmmessage; while (!done){
26
11691
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg"); sizeof(reinterpret_cast<const char *>(p)); ----------------------------------------------------------------------- ---------------------------------------- the compiler tells me that "reinterpret_cast from type "const char * " to type "unsigned char *"...
14
12294
by: moumita | last post by:
Hi All, I need to convert 4 bytes to an unsigned long. Suppose I have one array like unsigned char buf.I need to convert these 4 bytes into a single unsigned long. Is the following piece of code is right??Or is it a right approch to do that?? unsigned long temp; temp= (unsigned long) buff; temp | =((unsigned long) buff) << 8;
29
9956
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
8510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.