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 · 26 comments
Open
Labels
🐞 bug Issue describes a bug (crash or error) or undefined behavior. 👀 visual Issue with presentation of visual stimuli or graphics.

Comments

@Kodiologist
Copy link

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
Copy link
Contributor

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
Copy link
Author

Sure thing: Xorg.0.log

@djmannion
Copy link
Contributor

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
Copy link
Author

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

@djmannion
Copy link
Contributor

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
Copy link
Member

peircej 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
Copy link
Contributor

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
Copy link
Author

@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
Copy link
Author

@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
Copy link
Contributor

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
Copy link
Author

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

@sappelhoff
Copy link
Contributor

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
Copy link
Author

Kodiologist 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
Copy link

billbrod 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
Copy link
Contributor

cbrnr 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
Copy link
Contributor

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
Copy link
Contributor

cbrnr commented Feb 25, 2019

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

@mdcutone
Copy link
Member

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

@cbrnr
Copy link
Contributor

cbrnr 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
Copy link

caiki 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
Copy link

caiki 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
Copy link

m-guggenmos 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
Copy link
Contributor

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
Copy link

Oops, yes, that is indeed correct. Thanks!

@peircej
Copy link
Member

peircej 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
@shyamcody
Copy link

I had a problem of psychopy silently crashing without any error outputs. Even after trying out the solution of creation 20-intel.conf ; not finding out ramp issue I continued having the error. In my python 3.6.9, ubuntu 18.04 version, psychtoolbox created a problem of Fatal error: GC object already detected. according to this discourse discussion, I uninstalled psychtoolbox and then found it working.
Mentioning it for people reaching here like me.

@TEParsons TEParsons added 👀 visual Issue with presentation of visual stimuli or graphics. 🐞 bug Issue describes a bug (crash or error) or undefined behavior. labels Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Issue describes a bug (crash or error) or undefined behavior. 👀 visual Issue with presentation of visual stimuli or graphics.
Projects
None yet
Development

No branches or pull requests