Sign in to follow this  
majak

pointer expert?

Recommended Posts

majak    122
I need help here, can figure out this pointer stuff (if that is what's wrong..) I can build my project, but get this error when compiling: First-chance exception at 0x100033a8 in CreateTexture.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd. An unhandled exception of type 'System.NullReferenceException' occurred in CreateTexture.exe Additional information: Object reference not set to an instance of an object. This is why:
unsigned short size = nbPixels;							
PUCHAR *pixelBuffer = new PUCHAR[size];				
int var = retrieveAndRender(*pixelBuffer, the_Device);

How do I fix that? The function I'm calling is: OCT_API int retrieveAndRender(PUCHAR picRef, unsigned long adr); I'm not familiar with PUCHAR, so maybe I'm doing something wrong there?

Share this post


Link to post
Share on other sites
Andrew Russell    1394
Important information:
Quote:
0xCDCDCDCD : Used by Microsoft's C++ debugging heap to mark uninitialised heap areas

PUCHAR is probably "pointer to unsigned char".

Not 100% sure but try this code instead:

unsigned short size = nbPixels;
PUCHAR pixelBuffer = new unsigned char[size];
int var = retrieveAndRender(pixelBuffer, the_Device);

Share this post


Link to post
Share on other sites
smr    2468
0xcdcdcdcd is the code for uninitialized memory i think. When your code is compiled in debug mode, the compiler inserts code to place certain values in places as a debugging aid. This one is telling you that you've allocated a pointer somewhere and tried to derefrence it without pointing it at something first. Take a look at the definition of PUCHAR. I have a feeling that PUCHAR is declared as:


typedef UCHAR* PUCHAR;


Try this:


PUCHAR pixelBuffer = new UCHAR[size];
int var = retrieveAndRender(pixelBuffer, the_Device);

Share this post


Link to post
Share on other sites
majak    122
thanks, but both things give the same error.

Is it because I don't make it point to the first element in the array or??

Share this post


Link to post
Share on other sites
majak    122
The function I'm calling is in a DLL, and when I call it from LabVIEW there's nothing wrong, the_Device is 89868512 when debugging in LabVIEW and 4008080 in visual, the function where I get the device return 1 or 0 if there's an error. I have tried to set the_Device to 89868512 in visual, manually to see if it makes any difference, but it dosn't.

So I think it's the array, pixelBuffer, that I'm trying to send, that the problem.

Share this post


Link to post
Share on other sites
majak    122
Quote:
Original post by Rattrap
What's the input types of retrieveAndRender()?


The function looks like this:

OCT_API int retrieveAndRender(PUCHAR picRef, unsigned long adr);

Share this post


Link to post
Share on other sites
majak    122
I found out what was wrong..

Besides I was using the pointer thing wrong, so both of these do work =) I also should have used another kind of size, instead of short it should be byte, because the function thinks it get an array of with elements of bytes!!


PUCHAR pixelBuffer = new UCHAR[size];
int var = retrieveAndRender(pixelBuffer, the_Device);


PUCHAR pixelBuffer = new unsigned char[size];
int var = retrieveAndRender(pixelBuffer, the_Device);

Thank you for all your help ^..^

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this