pyglet.gl.ContextException: Unable to share contexts

2,207 views
Skip to first unread message

Daniel Gillet

unread,
Feb 8, 2015, 6:40:28 AM2/8/15
to pyglet...@googlegroups.com
Hello,

On my laptop when trying to launch this minimal code
import pyglet

pic = pyglet.image.load('image1.png', file=pyglet.resource.file('image1.png'))
texture = pic.get_texture()

window = pyglet.window.Window()

@window.event
def on_draw():
      window.clear()

pyglet.app.run()

I get this error message: pyglet.gl.ContextException: Unable to share contexts with this stack trace:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    window = pyglet.window.Window()
  File "C:\Python27\lib\site-packages\pyglet-1.2.0rc3-py2.7.egg\pyglet\window\win32\__init__.py", line 131, in __init__
    super(Win32Window, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\pyglet-1.2.0rc3-py2.7.egg\pyglet\window\__init__.py", line 559, in __init__
    self._create()
  File "C:\Python27\lib\site-packages\pyglet-1.2.0rc3-py2.7.egg\pyglet\window\win32\__init__.py", line 261, in _create
    self.context.attach(self.canvas)
  File "C:\Python27\lib\site-packages\pyglet-1.2.0rc3-py2.7.egg\pyglet\gl\win32.py", line 263, in attach
    super(Win32ARBContext, self).attach(canvas)
  File "C:\Python27\lib\site-packages\pyglet-1.2.0rc3-py2.7.egg\pyglet\gl\win32.py", line 208, in attach
    raise gl.ContextException('Unable to share contexts')
pyglet.gl.ContextException: Unable to share contexts

If I create the window before the texture = pic.get_texture(), it works correctly. I cannot reproduce this error on my desktop.

I believe this comes from 
pyglet\image\__init__.py(1502)create() 
id = GLuint()
which (I'm guessing here) is creating a context. So when trying to create the window, we have more than one OpenGL context and it throws an exception with my video card driver.

Should I post this in the Bitbucket Issues section?

Daniel.

Daniel Gillet

unread,
Feb 8, 2015, 7:54:51 AM2/8/15
to pyglet...@googlegroups.com
Obviously it's not the GLuint() which is to be incriminated... But with my little understanding of OpenGL, I guess that one of the OpenGL function must create an OpenGL context if none exists.

Daniel.

Daniel Gillet

unread,
Feb 12, 2015, 11:24:36 AM2/12/15
to pyglet...@googlegroups.com
No one can reproduce my problem maybe? It seems this issue doesn't get much love. :)

Dan.

Rob van der Most

unread,
Feb 12, 2015, 11:31:09 AM2/12/15
to pyglet...@googlegroups.com

I'll try to have a look after I released 1.2.0.

Rob

On 12 Feb 2015 17:24, "Daniel Gillet" <dan.gi...@gmail.com> wrote:
No one can reproduce my problem maybe? It seems this issue doesn't get much love. :)

Dan.

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Jonathan Gardner

unread,
Feb 12, 2015, 5:08:12 PM2/12/15
to pyglet...@googlegroups.com
Without trying the code, may I recommend trying to create the window before doing anything else?

--
Jonathan Gardner
jgar...@jonathangardner.net

claudio canepa

unread,
Feb 13, 2015, 2:37:46 AM2/13/15
to pyglet...@googlegroups.com
On Thu, Feb 12, 2015 at 1:24 PM, Daniel Gillet <dan.gi...@gmail.com> wrote:
No one can reproduce my problem maybe?

 Cannot repro in a system at hand ( win xp, py27, gpu ati radeon hd6570 with cataylst drivers 11.5 ), pyglet 1.2rc1 and 1.2.0 release. 
 
It seems this issue doesn't get much love. :)


Besides the focus to release from the pyglet side, I would guess the issue is probably hard to debug and very much non critical:

    hard: initial state for window and gl context is implicitly built trough a number of imports, so not easy to isolate parts to test, also problems in context sharing are usually linked to details in the specific video driver. 

    not critical: if instantiating the window first gives no problem, seems it is not a show stopper

So it would be nice to get this fixed, but probably low in priority


Daniel Gillet

unread,
Feb 13, 2015, 3:29:14 AM2/13/15
to pyglet...@googlegroups.com
Hi,
 
Thanks for all the replies. My configuration is Win 7, py27 or py34, gpu Intel HD Graphics4000 using either pyglet 1.2rc 1 or pyglet 1.2.0 release.

The reason for not creating the window first is only because of some code in Cocos2D library. More precisely, if using particle.py, you can see here that an image is loaded and its texture retrieved as a class attribute. So this code is run at import time, before I can create my window. A work around is to create my window before the import statement, but this is not really practical.

So for people like me having this "restriction" from the gpu, Cocos2D particle systems would not work out of the box. I posted a similar message on Cocos2D group discussion. The fix is either to change Cocos2D particle system so that this texture is only retrieved once the class is instanciated, or to fix the problem in Pyglet.

I'll try my best to find the problem. I'll let you know if there is anything I can find. I do understand the lack of interest if not many people face the same problem. But I can only say that at least 2 persons run into this problem: Qasim Khalil (from the Cocos2D discussion) and myself.

claudio canepa

unread,
Feb 13, 2015, 4:35:21 AM2/13/15
to pyglet...@googlegroups.com


On Fri, Feb 13, 2015 at 5:29 AM, Daniel Gillet <dan.gi...@gmail.com> wrote:
... 
So for people like me having this "restriction" from the gpu, Cocos2D particle systems would not work out of the box. I posted a similar message on Cocos2D group discussion. The fix is either to change Cocos2D particle system so that this texture is only retrieved once the class is instanciated, or to fix the problem in Pyglet.

 
Okay, I will do a delayed load for the next release so as cocos gets of the hook.


Rob

unread,
Feb 13, 2015, 5:14:47 AM2/13/15
to pyglet...@googlegroups.com
Can you also raise an issue in the bugtracker? Then it won't be forgotten.

Rob

Op vrijdag 13 februari 2015 10:35:21 UTC+1 schreef claudio canepa:

Richard Jones

unread,
Feb 13, 2015, 5:46:34 AM2/13/15
to pyglet...@googlegroups.com
Hi, you later post that you're using an Intel HD 4000 system. We've historically noticed that Intel systems don't support shared opengl contexts.

You can disable the automatic creation of a shadow context by setting the environment variable

    PYGLET_SHADOW_WINDOW=0

Note that if you do this then you must alter your application to always open its window first - if you don't and load images first you'll get all sorts of brokenness (and possibly segfaults).


      Richard

Oktay Acikalin

unread,
Feb 13, 2015, 8:02:45 AM2/13/15
to pyglet...@googlegroups.com
Also interesting for me! Is that properly documented so far that others can see it?

Richard Jones

unread,
Feb 13, 2015, 5:23:30 PM2/13/15
to pyglet...@googlegroups.com
Yes, it's documented here http://www.pyglet.org/doc/api/pyglet-module.html#options

(no, that's not ideal documentation)

Daniel Gillet

unread,
Feb 14, 2015, 11:02:07 AM2/14/15
to pyglet...@googlegroups.com
Thank you for all these information! I will try also to update my video driver and will let you know how it goes.

I've also played around, trying to find ways around this problem. Here is something I found. When creating a new context, if I don't use Win32ARBContext but Win32Context, the problem disappears...

I don't know if there's a way to 'downgrade' the context in case the exception gl.ContextException: Unable to share contexts is raised. But I thought this might be a solution to the problem. Unless using Win32Context instead of Win32ARBContext is out of question.

Not sure if I should raise this in the bug tracker, as it might just be a restriction of those Intel gpu chips.

Daniel.
Message has been deleted

Daniel Gillet

unread,
Feb 26, 2015, 9:19:32 AM2/26/15
to pyglet...@googlegroups.com
Hello everyone,

After installing the lasted drivers, the problem still persists. I realize that we are a good bunch of people with Intel GPU so it would be nice to find a solution.

As I said in my previous message, I noticed that using Win32Context instead of Win32ARBContext allows the use of wglShareLists on those Intel GPU. So my humble suggestion would be to change in the file gl/win32.py the method create_context (line 177) with this:

    def create_context(self, share):
        
if wgl_info.have_extension('WGL_ARB_create_context') and gl_info.get_vendor() != 'Intel':
            
return Win32ARBContext(self, share)
        
else:
            
return Win32Context(self, share)

In my case, it solves the problem. If this could be tested, we might make life easier for many people.

Dan.

Rob van der Most

unread,
Feb 26, 2015, 9:27:57 AM2/26/15
to pyglet...@googlegroups.com

That seems like a reasonable fix. Or can somebody give a reason why we need to stick to the arbcontext? If not I will add it to both 1.3 and 1.2.2

Rob

--

Rob

unread,
Feb 28, 2015, 11:42:18 AM2/28/15
to pyglet...@googlegroups.com
Could anybody with an Intel card send me the output of glxinfo? I want to check a few things before adding the workaround.

Rob

Op donderdag 26 februari 2015 15:27:57 UTC+1 schreef Rob:

That seems like a reasonable fix. Or can somebody give a reason why we need to stick to the arbcontext? If not I will add it to both 1.3 and 1.2.2

Rob

On 26 Feb 2015 15:19, "Daniel Gillet" wrote:
Hello everyone,

After installing the lasted drivers, the problem still persists. I realize that we are a good bunch of people with Intel GPU so it would be nice to find a solution.

As I said in my previous message, I noticed that using Win32Context instead of Win32ARBContext allows the use of wglShareLists on those Intel GPU. So my humble suggestion would be to change in the file gl/win32.py the method create_context (line 177) with this:

    def create_context(self, share):
        
if wgl_info.have_extension('WGL_ARB_create_context') and gl_info.get_vendor() != 'Intel':
            
return Win32ARBContext(self, share)
        
else:
            
return Win32Context(self, share)

In my case, it solves the problem. If this could be tested, we might make life easier for many people.

Dan.

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users+unsubscribe@googlegroups.com.

Rob

unread,
Feb 28, 2015, 12:04:15 PM2/28/15
to pyglet...@googlegroups.com
D'oh, glxinfo is of course Linux only. Any idea what tool will do the trick on Windows?

Rob

Op zaterdag 28 februari 2015 17:42:18 UTC+1 schreef Rob:

Tristam MacDonald

unread,
Feb 28, 2015, 4:54:19 PM2/28/15
to pyglet...@googlegroups.com
The OpenGL Extensions Viewer ought to produce a similar set of info on other platforms:

http://www.realtech-vr.com/glview/

- Tristam
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.

Rob

unread,
Mar 1, 2015, 4:38:01 AM3/1/15
to pyglet...@googlegroups.com
I now submitted the workaround to disable ARB contexts for Intel devices in pyglet-1.2-maintenance. But I would still want to try and find out if we can detect whether a device/driver has this problem.

Rob

Op zaterdag 28 februari 2015 22:54:19 UTC+1 schreef swiftcoder:
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Daniel Gillet

unread,
Mar 1, 2015, 8:42:59 AM3/1/15
to pyglet...@googlegroups.com
Hi,

I installed the OpenGL Extensions Viewer. Here is the report output (see attachment)

I hope this helps...

Dan.
glview-Intel(R) HD Graphics 4000-7.XML

magu...@gmail.com

unread,
Apr 11, 2015, 8:56:08 PM4/11/15
to pyglet...@googlegroups.com
I encountered the exact same problem with an ATI Radeon 9600, though from what seems like a different source.
I also had the latest drivers available
installed (Legacy which are no longer being maintained, so no chance of that changing). After doing a bit of digging I found that
the Radeon 9600 series has a known issue with "wgl.wglShareLists", disabling the Shadow Window directly after importing Pyglet seems
to solve this issue though.

I did encounter another bug afterward though, sometimes when closing the window it seems to close the Context before stopping the script,
so when the window closes it still runs the draw calls pulling and error. Not necessarily a fatal issue, but worth noting.
Reply all
Reply to author
Forward
0 new messages