ValueError: unsupported colormasks for alpha reference array

I'm getting the following exception from pygame 1.9.1 when trying to use pixels_alpha():

ValueError: unsupported colormasks for alpha reference array

The surface was created using Surface((w, h), SRCALPHA).

The masks it's using are: 00ff0000 0000ff00 000000ff ff000000

I can't see why this should cause it any problem. Anyone have any ideas?

(log in to comment)


I think you meant to use surfarray.pixels2d instead of surfarray.pixels_alpha. surfarray.pixels_alpha ONLY includes the alpha data, not the full ARGB data. Demonstration:

$ cat
import pygame
surface = pygame.Surface((2,2), pygame.SRCALPHA)
print pygame.surfarray.pixels_alpha(surface)
print pygame.surfarray.pixels2d(surface)
$ python
[[255 255]
 [255 255]]
[[4278204416 4278204416]
 [4278204416 4278204416]]
Maybe I should learn to read before I respond to messages. Ignore what I just said.
surfarray.pixels_alpha() uses the Surface.get_shifts() method to determine if it's able to create the array for a given surface. Is it possible that Surface.get_shifts() has become desynchronized with Surface.get_masks()? What is the output of get_shifts() for that surface?
I tracked this down to a bug in pygame 1.9.1. Essentially whoever wrote it left big-endian machines out in the cold. The relevant code is pure Python, so I've incorporated a fixed version of pixels_alpha into my code for now.