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

TypeError: unsupported operand type(s) for &: 'long' and 'LP_c_void' when using the pyglet backend #1779

Closed
alpinho opened this issue Mar 26, 2018 · 12 comments
Labels
🐞 bug Issue describes a bug (crash or error) or undefined behavior.

Comments

@alpinho
Copy link

alpinho commented Mar 26, 2018

Under python 2.7 and psychopy 1.90.0 I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Users\analuisa\gitrepos\cognitive_protocols\visual_protocols\retinotopy\retinoto.py in <module>()
    275         fixation_callback, pref_color = get_retino_fixation(number)
    276
--> 277         window = visual.Window(fullscr=False)
    278         show_init_screen(
    279             window, u"Chargement... \n", wait_key=None, with_fixation=False)

C:\Users\analuisa\Anaconda2\lib\site-packages\psychopy\visual\window.pyc in __init__(self, size, pos, color, colorSpace, rgb, dkl, lms, fullscr, allowGUI, monitor, bitsMode, winType, units, gamma, blendMode, screen, viewScale, viewPos, viewOri, waitBlanking, allowStencil, multiSample, numSamples, stereo, name, checkTiming, useFBO, useRetina, autoLog, *args, **kwargs)
    373
    374         # setup the context
--> 375         self.backend = backends.getBackend(win=self, *args, **kwargs)
    376         self.winHandle = self.backend.winHandle
    377         global GL

C:\Users\analuisa\Anaconda2\lib\site-packages\psychopy\visual\backends\__init__.pyc in getBackend(win, *args, **kwargs)
     30                              "there is no backend definition to match that "
     31                              "winType.".format(win.winType))
---> 32     return Backend(win, *args, **kwargs)
     33

C:\Users\analuisa\Anaconda2\lib\site-packages\psychopy\visual\backends\pygletbackend.pyc in __init__(self, win, *args, **kwargs)
    221         # store properties of the system
    222         self._driver = pyglet.gl.gl_info.get_renderer()
--> 223         self._origGammaRamp = self.getGammaRamp()
    224         self._rampSize = getGammaRampSize(self.screenID, self.xDisplay)
    225         self._TravisTesting = (os.environ.get('TRAVIS') == 'true')

C:\Users\analuisa\Anaconda2\lib\site-packages\psychopy\visual\backends\pygletbackend.pyc in getGammaRamp(self)
    320
    321     def getGammaRamp(self):
--> 322         return getGammaRamp(self.screenID, self.xDisplay)
    323
    324     @property

C:\Users\analuisa\Anaconda2\lib\site-packages\psychopy\visual\backends\pygletbackend.pyc in screenID(self)
    332                 _screenID = 0xFFFFFFFF & int.from_bytes(scrBytes, byteorder='little')
    333             else:
--> 334                 _screenID = 0xFFFFFFFF & scrBytes
    335         elif sys.platform == 'darwin':
    336             try:

TypeError: unsupported operand type(s) for &: 'long' and 'LP_c_void'

This protocol works fine with psychopy 1.85.3.

@alpinho
Copy link
Author

alpinho commented Mar 26, 2018

More info: this is under Windows 10 with pyglet 1.3.2.

@peircej
Copy link
Member

peircej commented Mar 26, 2018

Thanks for the info. Puzzling because the old code appears to be doing the same but didn't have a type error. I'll do my best to work it out though :-/

Are you sure that this version of pyglet worked with 1.85.3. I'm just wondering whether you might have updated both at the same time (and maybe something changed in pyglet)?

@hsogo
Copy link
Contributor

hsogo commented Apr 6, 2018

I'm also having trouble with this issue. My setup is Windows 10 X64, Python 2.7.10 X86, PsychoPy 1.90.0 and Pyglet 1.3.0.

I read source code of pyglet and found that the content of winHandle._dc (=scrBytes) seems to be set in pyglet.window.win32.Win32Window._create(). In this method, return value of _user32.GetDC() is set to _dc. _user32.GetDC() is actually ctypes.windll.user32.GetDC() as defined in pyglet/libs/win32/__init__.py.

Type of the return value of _user32.GetDC() are defined in lines 157 of pyglet/libs/win32/__init__.py as following.

# workaround for win 64-bit, see issue #664
_user32.GetDC.restype = c_void_p # HDC

Changing restype to HDC, PsychoPy can create pyglet window without error.
I think it difficult to fix this issue without editing pyglet codes.

@hsogo
Copy link
Contributor

hsogo commented Apr 6, 2018

FYI: replacing pyglet 1.3.0 with 1.2.4 seems to fix this issue in my setup. In addition, pyglet 1.3.0 works fine with Windows10 x64, Python 3.6.1 x64 and the latest PsychoPy.

@alpinho
Copy link
Author

alpinho commented Apr 6, 2018

At the beginning, when I installed PsychoPy 1.90.0, pyglet was giving me the following error:

NameError: name 'PUINT' is not defined

I have updated afterwards pyglet, according to what it is reported here. I used the following command line:

pip install --upgrade https://bitbucket.org/pyglet/pyglet/get/tip.zip

Then, it gave the error that I reported in the first instance of this thread. Afterwards, I downgraded my PsychoPy version to 1.85.3 and it solved the problem.

@Santihago
Copy link

With PsychoPy 1.90.1 / Pyglet 1.4 / Python 2.7 / Windows 7 32 bit I was having the same problem as described by alpinho and hsogo. Downgrading to Pyglet 1.24 solved the issue.

@hoechenberger
Copy link
Contributor

hoechenberger commented Apr 19, 2018

Wasn't this addressed via #1777 and #1787? Could you try again with latest master?

@hoechenberger hoechenberger added library 🐞 bug Issue describes a bug (crash or error) or undefined behavior. labels Apr 19, 2018
@hsogo
Copy link
Contributor

hsogo commented Apr 20, 2018

I tried the latest master with following setups. Both work fine now.

  • Windows 10 x64, Python 2.7.10 x86 and Pyglet 1.3.2
  • Windows 10 x64, Python 3.6.1 x64 and Pyglet 1.3.0

@hoechenberger
Copy link
Contributor

Great, thanks! So this seems to be resolved.

@hsogo
Copy link
Contributor

hsogo commented Apr 27, 2018

Sorry, I noticed that the issue is not fixed in Python 2.7 x86 and Pyglet 1.3.2.
It seems I made a mistake in switching back and forth between Pyglet 1.2.4 and 1.3.2.

@hoechenberger hoechenberger reopened this Apr 27, 2018
@sherdim
Copy link

sherdim commented May 24, 2018

Do not downgrade pyglet - it is nice.

The error fixed with patch to pygletbackend.py : 338

338c338
<                 _screenID = 0xFFFFFFFF & scrBytes
---
>                 _screenID = scrBytes

@peircej
Copy link
Member

peircej commented May 24, 2018

Thanks @sherdim I didn't know that works. But there are other installations where it's needed, so I'll apply that using a try...except and hopefully everything will be happy!

peircej added a commit to peircej/psychopy that referenced this issue Jul 2, 2018
fixes psychopy#1779

Where the error was: TypeError: unsupported operand type(s) for &: 'long'
and 'LP_c_void'

It turns out the code forcing the screen pointer into a long format int
wasn't necessary on the systems where the error occurred
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.
Projects
None yet
Development

No branches or pull requests

6 participants