# visual.Window() crashes with Pyglet

I have a large task program that I can usually get to run on Linux and on Windows. Upon trying to get it to run on a new Windows 10 machine, I found that I could no longer detect mouse clicks. So I upgraded PsychoPy to 1.90.0 with pip, but now I get a crash just from visual.Window(). Given a program

import sys
from psychopy import visual

print "AAAAAAAAA"; sys.stdout.flush()
win = visual.Window()
print "BBBBBBBBB"; sys.stdout.flush()


I get, upon trying to run the program in cmd.exe,

>python test.py
AAAAAAAAA
Traceback (most recent call last):
File "test.py", line 4, in <module>
win = visual.Window()
File "C:\Python27\lib\site-packages\psychopy\visual\window.py", line 375, in __init__
self.backend = backends.getBackend(win=self, *args, **kwargs)
File "C:\Python27\lib\site-packages\psychopy\visual\backends\__init__.py", line 32, in getBackend
return Backend(win, *args, **kwargs)
File "C:\Python27\lib\site-packages\psychopy\visual\backends\pygletbackend.py", line 223, in __init__
self._origGammaRamp = self.getGammaRamp()
File "C:\Python27\lib\site-packages\psychopy\visual\backends\pygletbackend.py", line 322, in getGammaRamp
return getGammaRamp(self.screenID, self.xDisplay)
File "C:\Python27\lib\site-packages\psychopy\visual\backends\pygletbackend.py", line 334, in screenID
_screenID = 0xFFFFFFFF & scrBytes
TypeError: unsupported operand type(s) for &: 'long' and 'LP_c_void'
Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method Window.__del__ of <psychopy.visual.window.Window object at 0x0000000004E37278>> ignored


I’m using a 64-bit Python 2.7.14 binary from python.org, and I originally installed PsychoPy with pip. pyglet is version 1.3.1.

1 Like

For the time being, I downgraded to PsychoPy 1.85.3, and I got click detection working by downgrading pyglet to 1.3.0.

2 Likes

I get a similar exception with Window 10 using Builder. I clean installed PsychoPy 3.0.6 64 bit (the same happens with 32 bit).

I create a new experiment and add an image (standard .gif file). Code attached.

I get this output when I run, just after entering the subject number:

testing_new_lastrun.py (5.6 KB)

#### Running: G:\My Drive\PsyLabs\Sam Rakover\SimUI\testing_new_lastrun.py

pygame 1.9.4
Hello from the pygame community. Contribute - pygame wiki
Traceback (most recent call last):
File “G:\My Drive\PsyLabs\Sam Rakover\SimUI\testing_new_lastrun.py”, line 62, in
blendMode=‘avg’, useFBO=True)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\visual\window.py”, line 386, in init
self.backend = backends.getBackend(win=self, *args, **kwargs)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\visual\backends_init_.py”, line 32, in getBackend
return Backend(win, *args, **kwargs)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\visual\backends\pygletbackend.py”, line 227, in init
self._origGammaRamp = self.getGammaRamp()
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\visual\backends\pygletbackend.py”, line 326, in getGammaRamp
return getGammaRamp(self.screenID, self.xDisplay)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\visual\backends\gamma.py”, line 128, in getGammaRamp
raise AssertionError(‘GetDeviceGammaRamp failed’)
AssertionError: GetDeviceGammaRamp failed
Exception ignored in: <bound method Window.del of <psychopy.visual.window.Window object at 0x000002408E0E8908>>
Traceback (most recent call last):
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\visual\window.py”, line 493, in del
self.close()
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\visual\window.py”, line 1277, in close
self.backend.close() # moved here, dereferencing the window prevents
AttributeError: ‘NoneType’ object has no attribute ‘close’

That error looks to be a bit different - it is unable to read the gamma table. Could you let us know what your video card and monitor setup is?

My setup is an HP Z240 workstation:
CPU: Xeon E3-1225 v5
Graphic card #1: Intel onboard - not connected to a monitor
Graphic card #2: NVidia Quadro K620 connected to 2 Dell U2415 monitors
System memory: 32 GB

One thing that I suspect of is the Windows 10 version. I recently updated to a stable beta build 18356 (it’s 1903).

Thanks,
Rani

Is there ‘10-bit output depth’ or any other quadro-specific settings set in the nvidia control panel? That’s about all I can think of as to why windows wouldn’t return a gamma table.

You could also try using the “glfw” backend (winType="glfw"), which uses different gamma functions. I’d be interested to hear if that works and, if so, what sort of gamma table it returns.

Hi @djmannion and thanks again.

I know I should have the 10-bit settings but only 8-bit is enabled. I also tried to disconnect one of the 2 screens to test if that causes the limitation.

Regarding ( winType="glfw" ), is it supported by Builder or should I use Code from now on?

Thanks,
Rani

Actually, I think it hasn’t been possible but I think we should absolutely add a backend setting to Builder/ExperimentSettings so you can switch to using ‘glfw’. I’ll bet @dvbridges could add that option in no time , so you should expect it in the next release series (3.1.x but not 3.0.x)

Hi Jon,

Thanks for your response and also for taking this to next step. So I guess this means that for the time being I will is code. I plan to test this tomorrow morning but if that doesn’t work I will revert my OS back to older version.

Kind regards,

Rani

All done, see below:

2 Likes

Hi,

I just want to update you that I reinstalled my computer with Windows ver. 1809. Now everything is working fine on PsychoPy 3.0.6. I think it might be wise, in order to “prepare for the worst”, to dive deeper and understand why the next phase of Windows (1903) failed for me.

Thanks guys, you’re really doing a great service.
Rani

Thanks for the update - I wonder what changed in 1903.

I have been thinking that it might be useful to add an option to Window to ignore all gamma setttings (applyGamma, maybe). At the moment, encountering a gamma problem stops execution. Perhaps we could continue to do that in the default case (applyGamma=True), but suggest to the the user in the error message to set applyGamma=False if they would like to proceed without gamma correction. Many (most?) users probably don’t need gamma correction, and it seems like gamma-related driver or operating system problems are coming up reasonably often.

I’m getting an OSError: The hardware look-up table (GetDeviceGammaRamp) was unable to be used.

It is solved if I show only on one screen, rather than extend the displays. I didn’t have this problem with PsychoPy2. Since I use builder, I don’t know how to set the Window parameter gammaErrorPolicy to "warn" or `“ignore”.

I tried self.gammaErrorPolicy = ‘ignore’ at the start of the first routine to no avail.

Best wishes,

Wakefield

Update

Note that in PsychoPy 3.2.4 we’ve reduced the use of the problematic Windows command that has the bug so that this will now only be a problem if you actually need the gamma to be controlled

For most experiments where gamma is not actually needed you can install 3.2.4 and the re should be no problem.

If you do need gamma to be controlled then you will need to turn off Extended Monitor mode or use a version of Windows that doesn’t have the bug.