Bug or Error Application crash

Hi,
I am testing Erode-Dilate filter implementation with following kernel:

#define M_ERODE_SIZE 10
texture<unsigned char, 2> tex;

global void ErodeTex(unsigned char *pErodeOutput, int w, int h)
{
unsigned char *pErode;
for ( int i = threadIdx.x; i < w; i += blockDim.x )
{
if ( tex2D( tex, (float)i, (float)blockIdx.x) > 0)
{
for (int j = -M_ERODE_SIZE; j < M_ERODE_SIZE; j++)
{
for (int k = -M_ERODE_SIZE; k < M_ERODE_SIZE; k++)
{
pErode = (unsigned char *) (((char *) pErodeOutput) + (blockIdx.x + j) * w + (i + k));
(*pErode) = 255;
}
}
}
}
}

extern “C” void MErodeFilter(cudaArray *idata, unsigned char *odata, int iw, int ih)
{
CUDA_SAFE_CALL(cudaBindTextureToArray(tex, idata));
ErodeTex<<<ih, 382>>>(odata, iw, ih );
CUDA_SAFE_CALL(cudaUnbindTexture(tex));
}

If I change the following two separate lines :

if ( tex2D( tex, (float)i, (float)blockIdx.x) >0 )
(*pErode) = 255;

with

if ( tex2D( tex, (float)i, (float)blockIdx.x) == 0)
(*pErode) = 0;

then the application crashes, even sometimes the system crashes. Is it a bug in the driver or there is something wrong with the above kernel code.

Best,

Hi, I have found the problem. I supposed that the memory access violations doesnt have side effect like accessing to the texture memory. thx.