unhandled exception at 0x ... in xxxx.exe:0xc0000005:access violation reading location 0x .....
For C + + beginners or careless people, it is easy to commit the error as shown:
So what is the cause of the error?
There is no doubt that there is only one, that is, reading a value or address that should not have been.
so how to solve it?
First thing, check if the parameters you passed are legal;
The second thing, if malloc has a piece of memory, you must remember free;
The third thing is whether you have assigned values or addresses that have been overrun.
To illustrate:
porg = Pcpicyuvorg->getlumaaddr (); for (y = 0, y < height-1; y++) {for (x = 0; x < width-1; x + +) {Pel a[4];//2x2a[ 0]=PORG[X]; A[1]=PORG[X+1]; a[2]= (Porg+stride) [x]; a[3]= (Porg+stride) [X+1];if (a[0]==255 && a[1]==255 && a[2]==255 && a[3]==255) {porg[x] = 255; PORG[X+1] = 255; (porg+stride) [x] = 255; (porg+stride) [x+1] = 255;} ELSE{PORG[X] = 0;porg[x+1] = 0; (porg+stride) [x] = 0; (porg+stride) [x+1] = 0;} x + = 1;} porg + = 2*stride;}
This code will appear with the error shown. So how to solve it?
porg = Pcpicyuvorg->getlumaaddr (); for (y = 0, y < HEIGHT/2; y++) {for (x = 0; x < width-1; x + +) {Pel a[4];//2x2a[ 0]=PORG[X]; A[1]=PORG[X+1]; a[2]= (Porg+stride) [x]; a[3]= (Porg+stride) [X+1];if (a[0]==255 && a[1]==255 && a[2]==255 && a[3]==255) {porg[x] = 255; PORG[X+1] = 255; (porg+stride) [x] = 255; (porg+stride) [x+1] = 255;} ELSE{PORG[X] = 0;porg[x+1] = 0; (porg+stride) [x] = 0; (porg+stride) [x+1] = 0;} x + = 1;} porg + = 2*stride;}
Obviously, the reason for the error is that the value of the overflow has been assigned.
If you encounter similar problems in the future, you can gradually check the above mentioned "three things" can be.
Unhandled exception at 0x ... in xxxx.exe:0xc0000005:access violation reading location 0x .....