title: OpenCL for-loop only working once
body: <p>The program is an Android application and needs to progress an mp4 image. The initialization can be found in this question: <a href="https://stackoverflow.com/questions/23696901/android-with-opencl-video-processing" title="init code">init code</a></p>
  
  <p>But I found out that the init code works with kernels who do <strong>not</strong> use <code>for</code> loops.
  When I have a nested for loop as in the example on the bottom of the post, only the first image will be processed and all the others will be black.</p>
  
  <p>Simple example:</p>
  
  <pre><code>1)
  init function
  execute kernel with for loops
  remove opencl function
  </code></pre>
  
  <p>=> all goes fine</p>
  
  <pre><code>2)
  init function 
  execute kernel **without** for loops
  execute kernel **without** for loops on next frame
  remove opencl function
  </code></pre>
  
  <p>=> all goes fine</p>
  
  <pre><code>3)
  init function
  execute kernel **with** for loops
  execute kernel **with** for loops on next frame
  remove opencl function
  </code></pre>
  
  <p><strong>=> first frame is processed, 2th frame is black</strong></p>
  
  <p>edge kernel:</p>
  
  <pre><code>__kernel void edgeKernel(__read_only  image2d_t  srcImage,
                            __write_only image2d_t  dstImage)
  {    
      const sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE |
                                 CLK_ADDRESS_REPEAT         |
                                 CLK_FILTER_NEAREST;
      int x = get_global_id(0);
      int y = get_global_id(1);
      int2 coords = (int2) (x,y);
  
      int i = 0;
      int j = 0;
      float4 bufferPixel,currentPixel;
      float sum = 0;
      int counter = 0;
      const float edgeKernel[9] = {0.0f,1.0f,0.0f,1.0f,-4.0f,1.0f,0.0f,1.0f,0.0f};
      currentPixel = read_imagef(srcImage,sampler,coords);
      for(i=-1;i&lt;=1;i++)
      {
          for(j=-1;j&lt;=1;j++)
          {
          coords = (int2)((x+i),(y+j));
          bufferPixel = read_imagef(srcImage,sampler,coords);
          //sum = sum + (bufferPixel.y * edgeKernel[counter]);
          sum = mad(bufferPixel.y,edgeKernel[counter],sum);
          counter++;
          }
      }
      if(sum&gt;255) sum=255;
      if(sum&lt;0) sum=0;
  
      currentPixel.x=sum;
      currentPixel.y=sum;
      currentPixel.z=sum;
  
      write_imagef(dstImage,coords,currentPixel);                           
  }
  </code></pre>
  
  <p><strong>I can not see what's wrong, I guess it's something with overlapping memory allocation but I'm clueless on what the solution might be.</strong></p>
  
  <p><strong>Edit1:</strong></p>
  
  <p><a href="https://github.com/degoossez/OVSR/blob/master/jni/OVSR.cpp" rel="nofollow noreferrer" title="opencl init">OpenCL code</a> is the link to the OpenCL code. Look for the <code>initOpenCL</code> and <code>nativeImage2DOpenCL</code> function. You should be able to find everything you need there.</p>