Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when calling glGetTexImage (atioglxx.dll)

Tags:

opengl

I'm experiencing a difficult problem on certain ATI cards (Radeon X1650, X1550 + and others).

The message is: "Access violation at address 6959DD46 in module 'atioglxx.dll'. Read of address 00000000"

It happens on this line:

glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_FLOAT,P);

Note:

  • Latest graphics drivers are installed.
  • It works perfectly on other cards.

Here is what I've tried so far (with assertions in the code):

  • That the pointer P is valid and allocated enough memory to hold the image
  • Texturing is enabled: glIsEnabled(GL_TEXTURE_2D)
  • Test that the currently bound texture is the one I expect: glGetIntegerv(GL_TEXTURE_2D_BINDING)
  • Test that the currently bound texture has the dimensions I expect: glGetTexLevelParameteriv( GL_TEXTURE_WIDTH / HEIGHT )
  • Test that no errors have been reported: glGetError

It passes all those test and then still fails with the message.

I feel I've tried everything and have no more ideas. I really hope some GL-guru here can help!

EDIT:

After concluded it is probably a driver bug I posted about it here too: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=295137#Post295137

I also tried GL_PACK_ALIGNMENT and it didn't help.

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.

Here is my updated 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);
like image 466
Ville Krumlinde Avatar asked Nov 14 '22 01:11

Ville Krumlinde


1 Answers

You might take care of the GL_PACK_ALIGNEMENT. This parameter told you the closest byte count to pack the texture. Ie, if you have a image of 645 pixels:

  • With GL_PACK_ALIGNEMENT to 4 (default value), you'll have 648 pixels.
  • With GL_PACK_ALIGNEMENT to 1, you'll have 645 pixels.

So ensure that the pack value is ok by doing:

glPixelStorei(GL_PACK_ALIGNMENT, 1)

Before your glGetTexImage(), or align your memory texture on the GL_PACK_ALIGNEMENT.

like image 87
tito Avatar answered Jan 05 '23 18:01

tito