psychopy.org | Reference | Downloads | Github

Bugfixes for "Unable to share contexts" and "Portaudio not initialized"


#1

I’ve spent much of this semester struggling to make a working Word Pronunciation Task. Along the way there have been some struggles with getting PsychoPy to run right on older (2009) computers.

BUG: "pyglet.gl.ContextException: Unable to share contexts […] “‘Window’ object has no attribute ‘useNativeGamma’”

SOLUTION: Add two lines to the top of the .py file, as explained here.

from __future__ import absolute_import, division
# Fix pyglet 'shared environment' error
import pyglet
pyglet.options['shadow_window']=False
# script continues as normal

BUG: “Portaudio not initialized” leads to crashes when using a microphone.

SOLUTION: Open Windows’ “Sound” panel, open the properties of your playback device, go to the advanced tab, and make sure that the default format is set to 44100Hz instead of 48000 Hz. As explained here.

For more details, see


#2

Could you help me test a possible fix for the pyglet window issue? Could you find the window.py file in your psychopy installation and find the line where the window is created, around line 1499. Try replacing it with this try...except code:

        try:
            self.winHandle = pyglet.window.Window(
                    width=w, height=h,
                    caption="PsychoPy",
                    fullscreen=self._isFullScr,
                    config=config,
                    screen=thisScreen,
                    style=style)
        except pyglet.gl.ContextException:
            # turn off the shadow window an try again
            pyglet.options['shadow_window']=False
            self.winHandle = pyglet.window.Window(
                    width=w, height=h,
                    caption="PsychoPy",
                    fullscreen=self._isFullScr,
                    config=config,
                    screen=thisScreen,
                    style=style)
            logging.warning("Pyglet shadow_window has been turned off. This is "
                            "only an issue for you if you need multiple "
                            "stimulus windows, in which case update your "
                            "graphics card and/or graphics drivers.")

Hopefully then you won’t need to tweak the code from your experiments manually in future!

The idea is that we’ll try to create the window once, and if it fails automatically try again with shadow window turned off. But I don’t know if pyglet will allow us two bites at the cherry, and I can’t test it myself.