Global Memory Access Violation Error


I have a device function that call another device function that have a for loop that go though an array of integer in structure as follow :-

__device__ bool mustAttack()
        for (int i = 0; i < 32; i++)
            if ( this->pieces[i] & ~(this->KING) == this->currentPlayer)
				if  (mayAttack(i))
					return true;
        return false;

I am getting memory access violation on the array of integer “pieces” because of the for loop. does anyone have a solution for this problem because I have to go through all the variables in the array ???

I really need your help guys.

DO you really think that small snippet of code is enough to evaluate this problem???

Your if-condition is probably not doing what you expect.
The C operator precedence of == is higher than binary &.

You must add braces if you wanted the bitwise AND to be evaluated first:
if ( (this->pieces[i] & ~(this->KING)) == this->currentPlayer)

If that’s not it, the code snippet is too small to pin-point other possible root causes of memory access violations.