Frustrating errors for a newbie.

48 views
Skip to first unread message

Dasleah

unread,
Sep 25, 2008, 8:20:46 PM9/25/08
to pyglet-users
Greetings all. I'm new to Pyglet and Python in general, so I'm sure
this is one of those errors that will be embarrasingly simply to
correct. But nevertheless, it's frustrating.

I'm running a simple copy-paste of the Hello World example from the
main website. As far as I can tell, I've installed Pyglet correctly,
and all my other extensions work fine. I've set the Python path (as
redundant as that may be) and I've got a fresh install of the most
recent Pyglet release. I'm using Python 2.5 on a Vista laptop (yeah,
yeah, I know) and whenever I run the script, I get this error, and
nothing else:

Traceback (most recent call last):
File "C:\Users\Aaron\Python\pyglet_test.py", line 2, in <module>
window = pyglet.window.Window()
File "C:\Python25\lib\site-packages\pyglet\window
\win32\__init__.py", line 423, in __init__
super(Win32Window, self).__init__(*args, **kwargs)
File "C:\Python25\lib\site-packages\pyglet\window\__init__.py", line
686, in __init__
self._create()
File "C:\Python25\lib\site-packages\pyglet\window
\win32\__init__.py", line 518, in _create
self.context._set_window(self)
File "C:\Python25\lib\site-packages\pyglet\window
\win32\__init__.py", line 364, in _set_window
raise gl.ContextException('Unable to share contexts')
ContextException: Unable to share contexts

Feel free to embarrass the hell out of me by making the solution to
this painfully obvious.

Alex Holkner

unread,
Sep 25, 2008, 8:33:47 PM9/25/08
to pyglet...@googlegroups.com

This is a known problem with several video devices, see
http://groups.google.com/group/pyglet-users/web/faq. Please let us
know if your device is not in the list, so we can add it. Make sure
you have the most up-to-date driver first.

Alex.

Dasleah

unread,
Sep 25, 2008, 8:43:35 PM9/25/08
to pyglet-users
Ah, yes, my apologies for firing off a question without putting more
effort into solving it myself ;) I do have one of the listed
incompatible video cards (the Intel 965, with most recent drivers) so
I guess that rather puts an unfortunate end to my Pyglet experience.
Oh well then, all I can do now is hope and pray... for a better
computer. Thanks for the quick answer, regardless.

On Sep 26, 10:33 am, "Alex Holkner" <alex.holk...@gmail.com> wrote:
> On Fri, Sep 26, 2008 at 10:20 AM, Dasleah <dasl...@gmail.com> wrote:

> This is a known problem with several video devices, seehttp://groups.google.com/group/pyglet-users/web/faq.  Please let us

Paul Hoskinson

unread,
Sep 25, 2008, 9:27:26 PM9/25/08
to pyglet...@googlegroups.com
I believe you can disable the creation of the shadow window to work
around the problem. This is done using an environment variable but I
don't remember what it is right now.

Ragzouken

unread,
Sep 26, 2008, 5:18:05 AM9/26/08
to pyglet-users
' If you're developing specifically for your (faulty) device, you can
set the environment variable PYGLET_SHADOW_WINDOW to 0 and limit
yourself to using a single window.'

On Sep 26, 2:27 am, Paul Hoskinson <plh...@gmail.com> wrote:
> I believe you can disable the creation of the shadow window to work  
> around the problem. This is done using an environment variable but I  
> don't remember what it is right now.
>

Alex Holkner

unread,
Sep 26, 2008, 5:40:18 AM9/26/08
to pyglet...@googlegroups.com
On 9/26/08, Ragzouken <Ragz...@gmail.com> wrote:
>
> ' If you're developing specifically for your (faulty) device, you can
> set the environment variable PYGLET_SHADOW_WINDOW to 0 and limit
> yourself to using a single window.'

... and only call OpenGL functions (and, by transitivity, many pyglet
functions) after creating that window.

Alex.

Ignatius Reilly

unread,
Sep 27, 2008, 8:46:16 PM9/27/08
to pyglet-users
What are the circumstances behind this problem? I have the same video
device and don't have any problems.

On Sep 25, 5:33 pm, "Alex Holkner" <alex.holk...@gmail.com> wrote:
> This is a known problem with several video devices, seehttp://groups.google.com/group/pyglet-users/web/faq.  Please let us

Alex Holkner

unread,
Sep 28, 2008, 3:19:30 AM9/28/08
to pyglet...@googlegroups.com
On 9/28/08, Ignatius Reilly <chad.alexan...@gmail.com> wrote:
>
> What are the circumstances behind this problem? I have the same video
> device and don't have any problems.

Each window in pyglet needs its own OpenGL context. Normally, OpenGL
contexts are completely separate from each other, so if you create a
texture, display list or VBO in one, you won't see it in the other.
Contexts can be "shared" with each other explicitly, which means the
contexts use the same set of textures, display lists and VBOs (and
some other object types not directly supported by pyglet).

Because it would be a nightmare to manage separate resources for each
open window, pyglet, by default, tries to share all OpenGL contexts it
creates. If the context can't be shared (for example, it's not
possible to share contexts that exist on separate video devices),
pyglet raises this exception ("Unable to share contexts") and gives
up.

You can, if you know what you're doing, create the context yourself
with the pyglet.gl module and pass this to the window; when you do
this you can set up any sharing or non-sharing system you like. Of
course, you must be careful to only use resources in each window
actually accessible by that window's context.

We've had reports from users with the listed video cards that they are
never able to share contexts, even on the same video device and with
the same pixel format (this is the default situation). This is due to
those devices not implementing the required functionality. I don't
believe this is technically a "bug" in those drivers, as the WGL, GLX
and AGL specifications don't put any minimum requirement on drivers to
provide this functionality at any time -- though most do.

Now, you're thinking to yourself, "but I'm only trying to open one
window!" This requires a little more explanation. In the early days
of pyglet 1.0, many users found it frustrating to have to create an
OpenGL context first, before creating any textures or setting any
OpenGL state. It just sort of turns out that the "default"
programming idiom people tend to use is to load all their resources
first, compile all their display lists, and _then_ open the main
window and start running.

It's not possible for pyglet to create textures and so on without a
current OpenGL context, so the default behaviour as of pyglet 1.1 is
to create an invisible window (the "shadow window") with its own GL
context as soon as the pyglet.gl module is imported. Because the
application's real windows will share objects with this hidden context
by default, there's now no problem in loading resources in any order
before any windows are created, and then using those resources in the
application window contexts.

As to why your device supports sharing of contexts and the earlier
poster's didn't; I can only guess that you have slightly different
firmware revisions, different video chipsets marked with the same
product code, different operating systems, or a different video mode
set up.

I'm looking to remedy this situation a little in pyglet 1.2: I
understand that some of the cards in the list that don't support
sharing of contexts created for on-screen drawing, do support sharing
contexts between an on-screen buffer and a pbuffer. By reimplementing
the "shadow window" as a pbuffer, some video devices previously unable
to be used with pyglet at all may become usable for single-window
applications (the vast majority, by my observation).

Cheers
Alex.

Static Vagabond

unread,
Sep 28, 2008, 12:39:05 AM9/28/08
to pyglet...@googlegroups.com
I came up against the problem with my Radeon HD4870
(http://code.google.com/p/pyglet/issues/detail?id=348&can=1&q=share&colspec=ID%20Status%20Type%20Milestone%20OpSys%20Summary)
Turned out I just needed to avoid IDLE, as a newcomer to Python myself
it didn't occur to me to use another development application until Alex
suggested it, perhaps it's a fairly common issue for new users?
Reply all
Reply to author
Forward
0 new messages