title: Error when calling glGetTexImage (atioglxx.dll)
body: <p>I'm experiencing a difficult problem on certain ATI cards (Radeon X1650, X1550 + and others).</p>
  
  <p>The message is: "Access violation at address 6959DD46 in module 'atioglxx.dll'. Read of address 00000000"</p>
  
  <p>It happens on this line:</p>
  
  <pre><code>glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_FLOAT,P);
  </code></pre>
  
  <p>Note:</p>
  
  <ul>
  <li>Latest graphics drivers are installed.</li>
  <li>It works perfectly on other cards. </li>
  </ul>
  
  <p>Here is what I've tried so far (with assertions in the code):</p>
  
  <ul>
  <li>That the pointer P is valid and allocated enough memory to hold the image</li>
  <li>Texturing is enabled: glIsEnabled(GL_TEXTURE_2D)</li>
  <li>Test that the currently bound texture is the one I expect: glGetIntegerv(GL_TEXTURE_2D_BINDING)</li>
  <li>Test that the currently bound texture has the dimensions I expect: glGetTexLevelParameteriv( GL_TEXTURE_WIDTH / HEIGHT )</li>
  <li>Test that no errors have been reported: glGetError</li>
  </ul>
  
  <p>It passes all those test and then still fails with the message.</p>
  
  <p>I feel I've tried everything and have no more ideas. I really hope some GL-guru here can help!</p>
  
  <p>EDIT:</p>
  
  <p>After concluded it is probably a driver bug I posted about it here too: <a href="http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=295137#Post295137" rel="nofollow">http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=295137#Post295137</a></p>
  
  <p>I also tried GL_PACK_ALIGNMENT and it didn't help.</p>
  
  <p>By some more investigation I found that it only happened on textures that I have previously filled with pixels using a call to glCopyTexSubImage2D. So I could produce a workaround by replacing the glCopyTexSubImage2d call with calls to glReadPixels and then glTexImage2D instead.</p>
  
  <p>Here is my updated code:</p>
  
  <pre><code>{
    glCopyTexSubImage2D cannot be used here because the combination of calling
    glCopyTexSubImage2D and then later glGetTexImage on the same texture causes
    a crash in atioglxx.dll on ATI Radeon X1650 and X1550.
    Instead we copy to the main memory first and then update.
  }
  //    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, PixelWidth, PixelHeight);  //**
  GetMem(P, PixelWidth * PixelHeight * 4);
  glReadPixels(0, 0, PixelWidth, PixelHeight, GL_RGBA, GL_UNSIGNED_BYTE, P);
  SetMemory(P,GL_RGBA,GL_UNSIGNED_BYTE);
  </code></pre>