Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu visual.Window() crashes with pyglet on XF86VidModeGetGammaRamp #2061

Open
Kodiologist opened this issue Oct 10, 2018 · 25 comments

Comments

@Kodiologist
Copy link

commented Oct 10, 2018

On PsychoPy 30066a5, Python 3.6.6, and Ubuntu 18.04, having just updated my Intel graphics drivers via the PPA at https://launchpad.net/~oibaf/+archive/ubuntu/graphics-drivers, running

from psychopy import visual

win = visual.Window()

crashes with

Traceback (most recent call last):
  File "/tmp/foofy.py", line 3, in <module>
    win = visual.Window()
  File "/usr/local/lib/python3.6/dist-packages/psychopy/visual/window.py", line 375, in __init__
    self.backend = backends.getBackend(win=self, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/psychopy/visual/backends/__init__.py", line 32, in getBackend
    return Backend(win, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/psychopy/visual/backends/pygletbackend.py", line 227, in __init__
    self._origGammaRamp = self.getGammaRamp()
  File "/usr/local/lib/python3.6/dist-packages/psychopy/visual/backends/pygletbackend.py", line 326, in getGammaRamp
    return getGammaRamp(self.screenID, self.xDisplay)
  File "/usr/local/lib/python3.6/dist-packages/psychopy/visual/backends/gamma.py", line 152, in getGammaRamp
    raise AssertionError('XF86VidModeGetGammaRamp failed')
AssertionError: XF86VidModeGetGammaRamp failed
0.5874  WARNING         Monitor specification not found. Creating a temporary one...
0.8026  WARNING         The size of the gamma ramp was reported as 0. This can mean that gamma settings have no effect. Proceeding with a default gamma ramp size.
Exception ignored in: <bound method Window.__del__ of <psychopy.visual.window.Window object at 0x7f0195db3e80>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/psychopy/visual/window.py", line 478, in __del__
    self.close()
  File "/usr/local/lib/python3.6/dist-packages/psychopy/visual/window.py", line 1116, in close
    self.backend.close()  # moved here, dereferencing the window prevents
AttributeError: 'NoneType' object has no attribute 'close'

I've seen this kind of thing previously on Windows, and #1982 (now closed) is likely related. My old workaround for this was to downgrade PsychoPy to 1.85.3, but I'm trying to upgrade my task program to Python 3 now that Python 2 is finally in its twilight years, and PsychoPy 1.85.3 doesn't support Python 3.

I've also looked at the pygame and glfw backends. However, pygame seems to be buggy (my stimuli are placed oddly) and glfw seems not to be feature-complete yet (psychopy.event.Mouse() crashes).

@djmannion

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

Mine used to just silently fail when the size of the gamma ramp was reported as 0 - it looks like we might need to do more to allow it to 'work' in this situation.

Can you post /var/log/Xorg.0.log (if it exists)?

@Kodiologist

This comment has been minimized.

Copy link
Author

commented Oct 11, 2018

Sure thing: Xorg.0.log

@djmannion

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

I might be reading it wrong, but it seems like it using the 'modesetting' driver (which now supports gamma, but didn't somewhat recently) rather than the intel driver. Can you explictly set the driver in an xorg conf and see if that changes anything?

@Kodiologist

This comment has been minimized.

Copy link
Author

commented Oct 11, 2018

Any hints on how to do that? I've always been pretty mystified by X configuration files.

@djmannion

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

I think it should be enough to put the following in /etc/X11/xorg.conf.d/20-intel.conf:

Section "Device"
    Identifier "Intel Graphics"
    Driver "intel"
EndSection
@peircej

This comment has been minimized.

Copy link
Member

commented Oct 11, 2018

Maybe his system is reporting 0, but is actually 1024, while we're reverting to a default of 256? Should we try and work out if any call to GetGammaRamp would have worked?

Kodi, you could try hard-coding the rampSize to be 1024 in

xDisplay, screenID, rampSize,

@djmannion

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

Worth a try. My guess is that it is due to the use of the modesetting driver in combination with an older version of xorg-server that doesn't have full gamma support (Mario Kleiner has some potentially relevant commits in February, after the release of the version used here) - but that's just a guess.

@Kodiologist

This comment has been minimized.

Copy link
Author

commented Oct 11, 2018

@djmannion Adding that configuration file fixed the problem. Thanks! It's pretty dumb that the package that's supposed to update your graphics drivers doesn't actually do that without more configuration.

@Kodiologist

This comment has been minimized.

Copy link
Author

commented Oct 11, 2018

@peircej That unfortunately doesn't seem to change anything, but adding origramps[:, :] = .5; return origramps right after origramps is defined seems to work okay.

@djmannion

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

Great! By 'fixed', do you mean that gamma can be changed and no warnings are emitted? Or that it runs without crashing but with warnings and no gamma functionality?

@Kodiologist

This comment has been minimized.

Copy link
Author

commented Oct 11, 2018

visual.Window(gamma = <whatever>) seems to work, with no warnings.

@sappelhoff

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2018

I was having the same problem on Ubuntu 16.04 running psychopy 1.90.2

The suggestion given above worked for me as well.

/etc/X11/xorg.conf.d/20-intel.conf did not exist for me though, and I had to create both the directory and the file. Any idea why there is the 20- prefix in the file name?

My specifications:

  *-display               
       description: VGA compatible controller
       product: Intel Corporation
       vendor: Intel Corporation
       physical id: 2
       bus info: pci@0000:00:02.0
       version: 07
       width: 64 bits
       clock: 33MHz
       capabilities: pciexpress msi pm vga_controller bus_master cap_list rom
       configuration: driver=i915 latency=0
       resources: irq:136 memory:ee000000-eeffffff memory:d0000000-dfffffff ioport:f000(size=64) memory:c0000-dffff
@Kodiologist

This comment has been minimized.

Copy link
Author

commented Nov 27, 2018

Any idea why there is the 20- prefix in the file name?

Leading numbers like those are used to control the order in which configuration files are read or scripts are run.

@billbrod

This comment has been minimized.

Copy link

commented Jan 7, 2019

I also had this issue, with psychopy 3.0.0, python 3.6.0, and Ubuntu 18.04, on a new laptop with integrated Intel graphics and an NVIDIA GPU. Updating my drivers, adding the 20-intel.conf file, and restarting my machine worked for me.

@cbrnr

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2019

I'm having the same issue with PsychoPy 3.0.4 on Arch Linux, Wayland, and an NVIDIA GPU (using the proprietary nvidia driver). Is there a more general solution for this problem that doesn't involve creating an X.org Intel config file?

@djmannion

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2019

I'm having the same issue with PsychoPy 3.0.4 on Arch Linux, Wayland, and an NVIDIA GPU (using the proprietary nvidia driver). Is there a more general solution for this problem that doesn't involve creating an X.org Intel config file?

That setup should work fine - it is pretty much what I use, except for the Wayland aspect. I haven't come across any reports of Wayland being used. The Arch wiki seems to suggest that gamma handling is different under Wayland.

@cbrnr

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2019

You're right, everything works when I switch to Xorg.

@mdcutone

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

Try using the 'glfw' backend, I believe it supports Wayland.

@cbrnr

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2019

Yes, I have to use glfw anyway because pyglet gives me only half the FPS. I didn't try that on Wayland though - since it works on Xorg I'm happy.

@caiki

This comment has been minimized.

Copy link

commented Mar 11, 2019

Maybe his system is reporting 0, but is actually 1024, while we're reverting to a default of 256? Should we try and work out if any call to GetGammaRamp would have worked?

Kodi, you could try hard-coding the rampSize to be 1024 in
psychopy/psychopy/visual/backends/gamma.py

Line 147 in 30066a5

xDisplay, screenID, rampSize,

I changed the value of rampSize to 1024, however it did not work for me.
Psychopy was working well with ubuntu 16 and for some strange reason it was updated to 18 and now it does not work, even I tried to reinstall it.

@caiki

This comment has been minimized.

Copy link

commented Mar 11, 2019

Maybe his system is reporting 0, but is actually 1024, while we're reverting to a default of 256? Should we try and work out if any call to GetGammaRamp would have worked?
Kodi, you could try hard-coding the rampSize to be 1024 in
psychopy/psychopy/visual/backends/gamma.py
Line 147 in 30066a5
xDisplay, screenID, rampSize,

I changed the value of rampSize to 1024, however it did not work for me.
Psychopy was working well with ubuntu 16 and for some strange reason it was updated to 18 and now it does not work, even I tried to reinstall it.

I do not know very well what is xorg, however I got the option to start Gnome xorg in my ubuntu, I decided to try that and it worked. Thanks for the comments above.

@m-guggenmos

This comment has been minimized.

Copy link

commented Mar 22, 2019

Hi,

in my case with Kubuntu 18.04 on KDE (Plasma 5.15.3), Python 3.7.2, PsychoPy 3.0.6 none of the above suggestions worked, i.e. I am still getting the AssertionError('XF86VidModeGetGammaRamp failed').

I followed all steps mentioned in #2082. I tried both hard-coding the rampSize to 1024 and creating the mentioned file /etc/X11/xorg.conf.d/20-intel.conf, without success.

Output of lspci | grep VGA:
00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)

Here my Xorg.0.log

Thanks
Matthias

Update: Commenting out the lines

if not `success:`
            raise AssertionError('XF86VidModeGetGammaRamp failed')

or using winType='glfw' "solves" the problem.

@djmannion

This comment has been minimized.

Copy link
Contributor

commented Mar 22, 2019

Your Xorg.0.log shows:

[     5.137] (II) LoadModule: "intel"
[     5.137] (WW) Warning, couldn't open module intel
[     5.137] (II) UnloadModule: "intel"
[     5.137] (II) Unloading intel
[     5.137] (EE) Failed to load module "intel" (module does not exist, 0)

It looks like you would need to install the intel graphics drivers, to get the pyglet solution to work.

@m-guggenmos

This comment has been minimized.

Copy link

commented Mar 26, 2019

Oops, yes, that is indeed correct. Thanks!

@peircej

This comment has been minimized.

Copy link
Member

commented Aug 7, 2019

So, conceivably we could write the intel.conf file for the user with something like the below. It doesn't quite solve the problem because they'd still need to restart the machine, but it might help?

import subprocess as sp
from askpass import AskPass

folder = "/etc/X11/xorg.conf.d"
filename = "/etc/X11/xorg.conf.d/20-intel.conf"
localfile = 'intel.conf'

prompt=("Intel card needs a config file installing. "
        "Please insert an admin password to continue")
        
with AskPass(prompt=prompt, timeout=30) as ask:
  success = False
  for psswd in ask:
    try:
            
        proc = sp.Popen(["echo {} | sudo -S mkdir -p '{}'"
                         .format(psswd, folder)], 
            shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
        output, error=proc.communicate(timeout=0.5)
        assert not proc.returncode
        fullCmd = ('echo {} | sudo -S cp {} {}'
                   .format(psswd, localfile, filename))
        proc = sp.Popen([fullCmd], 
            shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
        output, error=proc.communicate(timeout=0.5)
        assert not proc.returncode
        logging.info("Created intel.conf")
        success = True
        break
    except AssertionError as e:
        # what went wrong?
        print(output.decode('utf-8'))
        print(error.decode('utf-8'))
    except sp.TimeoutExpired as e:
        logging.info('Bad password')
  else:
    print("Failed to create intel.conf")
    ```
@peircej peircej changed the title visual.Window() crashes with pyglet Ubuntu visual.Window() crashes with pyglet on XF86VidModeGetGammaRamp Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.