moderngl: Wayland: Context creation failed

Upgrading from moderngl 5.5.3 to 5.6.4

Traceback (most recent call last):
  File "/home/istvan/Work/Mollia/mollia_window_linux/test_main_window_mouse.py", line 7, in <module>
    ctx = mgl.create_context()
  File "/home/istvan/.local/lib/python3.10/site-packages/moderngl/context.py", line 1619, in create_context
    ctx.mglo, ctx.version_code = mgl.create_context(glversion=require, mode=mode, **settings)
  File "/home/istvan/.local/lib/python3.10/site-packages/glcontext/__init__.py", line 93, in create
    return x11.create_context(**kwargs)
Exception: (detect) glXGetCurrentContext: cannot detect OpenGL context
Linux fedora 5.17.12-300.fc36.x86_64 #1 SMP PREEMPT Mon May 30 16:56:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

UPDATE: The problem seems to be Wayland related. No crash on X11 session.

just tested it: version 6.0 from the main branch (commit e175d069a13fd7bbc38e34fb8cfce447d91e0ff5) works on wayland !

I have errors on some buffer creation I did not had before, meaning moderngl 6 is less forgiving than 5, anyway I will easily fix that:

  File "/home/jimy/.local/lib/python3.11/site-packages/madcad/displays.py", line 389, in __init__
    self.vb_faces = scene.ctx.buffer(np.array(faces, 'u4', copy=False))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jimy/.local/lib/python3.11/site-packages/moderngl/__init__.py", line 1538, in buffer
    res.mglo, res._size, res._glo = self.mglo.buffer(data, reserve, dynamic)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: ndarray is not C-contiguous

For the moment, I think using the main branch of moderngl is fine. I will tell the madcad users to do so as well if they need to run on wayland. Anyway, since moderngl 6 is a major, I will only bump the minimum moderngl required in my projects when you will have introduced the breaking changes.

Thanks for having fixed this and for the quick answers !

ValueError: ndarray is not C-contiguous

I will add an issue for this, I already solved this for zengl, basically C-contiguous is not required. When not provided a copy is created temporarily, it is up to the user to provide contig memory to avoid the copy. It is fast anyways.

I need find what changed in moderngl 5.10 about context management

  • ModernGL 5.9 uses only the glcontext opengl context detection
  • ModernGL 5.10 adds a new way to detect opengl contexts better, this is only available in get_context
  • ModernGL 6.x will only use the new way by default.

This is only what changed regarding the context management.

The new way we detect opengl contexts is trying for egl and falls back for x11. I reopen the issue until we fix it for your case.

Any news on this ? I get the same error on debian 12 using wayland, and likewise no problem using Xorg (of course xorg tends to be deprecated so I would like not to use it)