pyglet: Erratic error: pyglet.gl.lib.GLException: (0x1281): Invalid value. A numeric argument is out of range.

I am struggling with an erratic error. I get it when playing a video. I tried different format, mp4, m4v but seems not related to the video itself. The video plays well, following the doc example. But after some restart of the app, it fails. If I reboot the computer or unplug/replug the external monitor, the error generally goes away. But it appears again later, even if I modify other parts of the app not related to the player. I got some opengl errors during the early dev of my app but it was always my fault. Here I don’t have any idea why this error appears randomly.

The trace:

Traceback (most recent call last):
  File "/home/user/src/app/./myapp.py", line 262, in <module>
    Application().run()
  File "/home/user/src/app/./myapp.py", line 115, in run
    pyglet.app.run()
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/app/__init__.py", line 76, in run
    event_loop.run(interval)
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/app/base.py", line 151, in run
    timeout = self.idle()
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/app/base.py", line 212, in idle
    self.clock.call_scheduled_functions(dt)
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/clock.py", line 227, in call_scheduled_functions
    item.func(now - item.last_ts, *item.args, **item.kwargs)
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/media/player.py", line 460, in update_texture
    self._texture.blit_into(image, 0, 0, 0)
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/image/__init__.py", line 1469, in blit_into
    self.owner.blit_into(source, x + self.x, y + self.y, z + self.z)
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/image/__init__.py", line 1364, in blit_into
    source.blit_to_texture(self.target, self.level, x, y, z)
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/image/__init__.py", line 823, in blit_to_texture
    glTexSubImage2D(target, level,
  File "/home/user/src/venv/lib/python3.10/site-packages/pyglet/gl/lib.py", line 79, in errcheck
    raise GLException(f'(0x{error}): {msg}')
pyglet.gl.lib.GLException: (0x1281): Invalid value. A numeric argument is out of range.
AL lib: (EE) alc_cleanup: 1 device not closed

pyglet info

I spent hours on this, now I don’t have any more ideas…

Thanks for your help.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

After some investigation in the lazy loading and @benmoran56 comment about modules loading:

TYPE_CHECKING = True

before importing pyglet solves the problem to run the app in vscod/ium… No more lazy load and no more error.

Code involved: https://github.com/pyglet/pyglet/blob/f10c4d2bad103d0370f3700c1cd9071a2f3fccfd/pyglet/__init__.py#L333-L374

Does anybody got this problem already? What to do?

Another information: I launched the app more than 10 times outside vscode debugger, it never failed. Back to vscodium, failed again (I get the same errors when quitting, see above).

So I guess the debugger is involved here… Do you have any information about that? Any advice? pyglet.options tricks that could help?

Thanks.

Common launch config…

        {
            "name": "Standalone",
            "type": "python",
            "request": "launch",
            "program": "myapp.py",
            "console": "integratedTerminal", 
            "justMyCode": true,
            "args": [
                "--project",
                "../project-sample"
            ]
        },

Yes, importing the media module does cause it to initialize the audio driver interface. If you only import pyglet, then other modules are behind a lazy loading proxy.

Is this happening with one source or different sources? Can you provide a source that is causing the error? I do see you are using ffmpeg 4.3. I would suggest upgrading to ffmpeg 4.4 or 5.x if possible.