#251 hasGLExtension fail wrt circular import

GL (74)

Given a 3.0+ forward-compatible context, that is, with glGetString barking at GL_EXTENSIONS, "from OpenGL.GL import *" may fail if one of OpenGL.GL.VERSION.GL_* submodules with version below 3.0 calls hasGLExtension() due to the fact that until "from OpenGL.GL.VERSION.GL_3_0 import *" line is executed in OpenGL/GL/__init__.py, the line "from OpenGL.GL import GL_NUM_EXTENSIONS, glGetStringi, glGetIntegerv" is guaranteed to throw an ImportError.

Suggested solution:

replace the aforementioned import statement in the hasExtension() function with the following two lines:

from OpenGL.GL.VERSION.GL_3_0 import GL_NUM_EXTENSIONS, glGetStringi
from OpenGL.GL import glGetIntegerv

Works for me.

Attached patch: the above fix plus a couple of nits to make it all work under Python 3.2


  • Mike C. Fletcher

    I've merged approximately this patch in.

    I reverted the "as" changes, as I don't believe I've ever officially announced dropping support for Python 2.5 (though I likely should some day soon). The change that would break unicode string checking on Python 2.x was also not included (AFAIK that code would work perfectly well on Python 3.x); there was a real reason to say "string or unicode" there. I had to add an alias for the __bool__ as well so that earlier Python's would still be able to do boolean checking.

  • Mike C. Fletcher

    • status: open --> open-fixed
  • Alexander Sabourenkov

    Thanks for quick reaction.

    There is another major problem.

    Now hasGLExtension() is called recursively on the first call. That is, at the first call we get to "from OpenGL.GL.VERSION.GL_3_0 import ...", which does "from OpenGL.GL.ARB.vertex_array_object import *", which in turn ends up calling hasGLExtension().

    The problem is that at the time of that second call glGetStringi()'s restype is not yet set. Thus it returns GLubytearrays or something, which leads to ARB_vertex_array_object extension be declared unavailable.

    The attached patch fixes the issue, moving restype assignment to above the extension imports.

    Those two calls to hasGlExtension() end up doing the work twice. This isn't so much a problem in itself, just not quite elegant.

  • Alexander Sabourenkov

    On the ' except ... as ' issue:

    Since the old syntax prevents it working on Python 3.x, and since the err variable isn't used anyway, I propose the line to be changed to just "except error.NullFunctionError:".

    On the "isinstance( name, ( str, unicode)):"

    "unicode" builtin was removed in Python 3.0. Thus it also breaks stuff under 3.0 and newer. I didn't dig to understand why it's there. To make it work though I suggest doing something like:

    nametypes = ( str, unicode)
    except NameError:
    nametypes = ( bytes, str)

    if not isinstance(name, nametypes):

  • Mike C. Fletcher

    You mean 2to3 *isnt'* converting the source code properly? It was supposed to convert references to unicode to str and exception syntax over to the 3.x syntax. Hrm.

    Circular import I'll have to look at again when I get a chance.

  • Mike C. Fletcher

    Oh, missed that there was a patch... okay, will apply it tonight.

  • Alexander Sabourenkov

    I withdraw that comment about except and stuff, that was indeed a local distutils breakage on my system. Thank you.


Log in to post a comment.