Skip to content

ImGui crashing when using OpenGL context 3.2+ even though GPU and driver support 4.6 #375

@aleksandaratanasov

Description

@aleksandaratanasov

I am trying to check something in my OpenGL application (uses the latest versions of PyGame, PyOpenGL and PyImGui packages) with RenderDoc. However, RenderDoc tells me that my app's OpenGL context is not 3.2+.

I checked my specs using glxinfo

OpenGL version string 4.6.0 NVIDIA 535.171.04

leading to the conclusion that anything 3.x should be fine.

I tried setting up the major and minor version for the OpenGL context

pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MAJOR_VERSION, 3)
pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MINOR_VERSION, 3)

before calling

pygame.display.set_mode(display, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE)

Before doing that, using pygame.display.gl_get_attribute() would return 2.2. The changes were applied and I got 3.3.

However, after I set the version properly ImGUI is crashing with the following error:

Traceback (most recent call last):
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/OpenGL/latebind.py", line 41, in __call__
    return self._finalCall( *args, **named )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not callable
 
During handling of the above exception, another exception occurred:
 
Traceback (most recent call last):
  File "/home/user/Projects/CGI/visualizer/renderer.py", line 353, in <module>
    main(logger, config)
  File "/home/user/Projects/CGI/visualizer/renderer.py", line 248, in main
    gui = GUI(width, height, logger, wireframe_enabled, bbox_enabled, zoom_factor, transl_factor, dataloader)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Projects/CGI/visualizer/Gui.py", line 12, in __init__
    self.impl = PygameRenderer()
                ^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/imgui/integrations/pygame.py", line 14, in __init__
    super(PygameRenderer, self).__init__()
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/imgui/integrations/base.py", line 18, in __init__
    self.refresh_font_texture()
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/imgui/integrations/opengl.py", line 251, in refresh_font_texture
    gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_ALPHA, width, height, 0, gl.GL_ALPHA, gl.GL_UNSIGNED_BYTE, pixels)
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/OpenGL/latebind.py", line 45, in __call__
    return self._finalCall( *args, **named )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/OpenGL/wrapper.py", line 877, in wrapperCall
    raise err
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/OpenGL/wrapper.py", line 870, in wrapperCall
    result = wrappedOperation( *cArguments )
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/CGI/lib/python3.11/site-packages/OpenGL/error.py", line 228, in glCheckError
    raise GLError(
OpenGL.error.GLError: GLError(
        err = 1281,
        description = b'invalid value',
        baseOperation = glTexImage2D,
        pyArgs = (
                GL_TEXTURE_2D,
                0,
                GL_ALPHA,
                512,
                64,
                0,
                GL_ALPHA,
                GL_UNSIGNED_BYTE,
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0...,
        ),
        cArgs = (
                GL_TEXTURE_2D,
                0,
                GL_ALPHA,
                512,
                64,
                0,
                GL_ALPHA,
                GL_UNSIGNED_BYTE,
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0...,
        ),
        cArguments = (
                GL_TEXTURE_2D,
                0,
                GL_ALPHA,
                512,
                64,
                0,
                GL_ALPHA,
                GL_UNSIGNED_BYTE,
                b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0...,
    )
)

I was unable to find info right out of the bat regarding the ImGUI integration with PyGame and where a specific version is required.

I played around with the major and minor numbers and I can get ImGUI to work in 3.1. Anything above that leads to a crash. I am unable to find information on OpenGL 3.1 in ImGui's documentation.

Is this fixable? Do I have to build from source to get the latest ImGUI and the Python bindings to work together?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions