Indexing inside the range getting llegal memory access was encountered error

hey guys ; I have been dealing with problem recently that
double * ptr_d1, *ptr_d2,*ptr_d0;

cudaMalloc(&ptr_d0,sizeof(double)*Len1);
cudaDeviceSynchronize();
//Kernel1<<<mx,maxThreads>>>(ptr_d0,...);
cudaMalloc(&ptr_d1,sizeof(double)*Len2);
cudaMalloc(&ptr_d2,sizeof(double)*Len2);
cudaMalloc(&anotherPtr,sizeof(int)*Len0);
cudaDeviceSynchronize();
KernelFails<<<mx,mxthp>>>(ptrd1,...);

then i get
an illegal memory access was encountered
Sync: an illegal memory access was encountered
but if i use ptrd2 my kernel works fine
i have checked the kernel multiple time and i know it doesnt
index any array out of its size
also when i change the index of ptr_d2 into 0 (inside the kernel )
it works with no error
what could be a cause and solutions for this error

i have checked the kernel multiple time and i know it doesn’t index any array out of its size

Well, you probably have a bug you’ve missed. Try using a debugger, or gradually commenting-out parts of your kernel’s work and/or exiting early for certain blocks and threads, to pinpoint where the invalid access happens.

A possible explanation of why you’re not failing with the second pointer could be be an array access using a negative index - but I’m just speculating.