LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ColorMapEntry Structure fails with General 'Protection Fault'

Hi,
I am using the Plotscaledintensity() function in my application code, running on CVI 7.1. To create the ColorMapArray, I need to perform the following operation: I get a General 'Protection Fault' failure and the application terminates.

Following is the code:

typedef struct
{
ColorMapEntry *colormaparray;
int numberofColors;
int HiColor;
}colormapstruct;

colormapstruct *colormaprec;


colormaprec->HiColor = 0x0;
colormaprec->numberofColors = 7;

// PGM FAILS WHEN THE COLOR VARIABLE IS INPUT WITH VALUES: FOLLOWING LINES OF CODES
colormaprec->colormaparray[0].color = 0xff00ff; //VIOLET
colormaprec->colormaparray[1].color = 0x800080; //INDIGO
colormaprec->colormaparray[2].color = 0x0000ff; //BLUE
colormaprec->colormaparray[3].color = 0x00ff00; //GREEN
colormaprec->colormaparray[4].color = 0xffff00; //YELLOW
colormaprec->colormaparray[5].color = 0xff8000; //ORANGE
colormaprec->colormaparray[6].color = 0xff0000; //RED

The Error that I receive:
FATAL RUN-TIME ERROR: "commontribo.c", line 9231, col 5, thread id 0x00000E28: The program has caused a 'General Protection' fault at 001B:004CB3FB.

Same piece of code worked fine in CVI 6.0 environment.

Any suggestions..???

- Dwivedi
0 Kudos
Message 1 of 3
(3,133 Views)
Based on the code you posted, my guess would be that you are not allocating memory for the colormaparray member of the colormapstruct structure (or you are allocating too little memory). Either of these could cause a GPF as you will be trying to access memory that is not allocated or possibly even following a bad pointer (if no memory was ever allocated).

/* ... */
colormaprec->numberofColors = 7;

/* try adding this line here */
colormaprec->colormaparray = malloc (colormaprec->numberofColors * sizeof (ColorMapEntry));

/* ... */

If this is the case then the fact that the code ever worked was probably just a coincidence but it's a good place to start looking, at least. If you just omitted posting the allocation code, maybe you could post a small example of this happening so I can look into this further.

Regards,

Alex
0 Kudos
Message 2 of 3
(3,125 Views)
Thanks Alex,
I figured it out too. It was the memory allocation problem.
Thanks once again.
Dwivedi
0 Kudos
Message 3 of 3
(3,122 Views)