pygame.surfarray.make_surface(numpyarray) gives IndexError

Bug #1336214 reported by Andrew Kay
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
pygame (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Feeding a numpy array to make_surface gives an error:

to reproduce:
$ python
>>> import numpy
>>> import pygame
>>> a = numpy.zeros((10,20,3), numpy.uint8)
>>> pygame.surfarray.make_surface(a)

output:
    IndexError: bytes to write exceed buffer size
expected:
    <Surface(10x20x32) SW)>

Stepping through inside, it seems that the buffer has the right size, and the data is the right length at the point the buffer write occurs. But the buffer write fails (and I can't step that)

I'm 99% certain that this worked before I upgraded from Kubuntu 13.10 to 14.04

### transcript
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
>>> import numpy
>>> import pygame
>>> a = numpy.zeros((10,20,3), numpy.uint8)
>>> pygame.SurfaceArray.make_surface(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'SurfaceArray'
>>> pygame.surfarray.make_surface(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pygame/surfarray.py", line 243, in make_surface
    return numpysf.make_surface (array)
  File "/usr/lib/python2.7/dist-packages/pygame/_numpysurfarray.py", line 368, in make_surface
    blit_array (surface, array)
  File "/usr/lib/python2.7/dist-packages/pygame/_numpysurfarray.py", line 437, in blit_array
    surface.get_buffer ().write (data, 0)
IndexError: bytes to write exceed buffer size

$ lsb_release -rd
Description: Ubuntu 14.04 LTS
Release: 14.04

$ apt-cache policy python-pygame
python-pygame:
  Installed: 1.9.1release+dfsg-9ubuntu1
  Candidate: 1.9.1release+dfsg-9ubuntu1
  Version table:
 *** 1.9.1release+dfsg-9ubuntu1 0
        500 http://gb.archive.ubuntu.com/ubuntu/ trusty/universe amd64 Packages
        100 /var/lib/dpkg/status

Revision history for this message
Andrew Kay (music1) wrote :

sorry. error copying steps to reproduce. Should have been

$ python
>>> import numpy
>>> import pygame
>>> a = numpy.zeros((10,20,3), numpy.uint8)
>>> pygame.surfarray.make_surface(a)

output:
    IndexError: bytes to write exceed buffer size
expected:
    <Surface(10x20x32) SW)>

Further testing shows it works on a fresh install of Mint.
Failing on Kubuntu 14.04 LTS
Working on Xubuntu 12.04.4 LTS

description: updated
description: updated
Revision history for this message
Andrew Kay (music1) wrote :

This problem doesn't occur if I build pygame myself.

So is there some problem with the packaging?

please?

thanks

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in pygame (Ubuntu):
status: New → Confirmed
Revision history for this message
Florent Flament (florentflament) wrote :

Same error on Ubuntu 14.04 (Trusty)..

Revision history for this message
Florent Flament (florentflament) wrote :

By the wat, I found an ugly workaroud:

 >>> import pygame
 >>> surface = pygame.Surface((100, 100))
 >>> data = "abcdefg"
 >>> buf = surface.get_buffer()
 >>> buf.write(data, 0)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 IndexError: bytes to write exceed buffer size
 >>> buf.write(data*1, 0)
 >>>

Revision history for this message
illume (illume) wrote :

This issue has been fixed in pygame 1.9.3+

>>> import pygame
>>> import numpy
>>> a = numpy.zeros((10,20,3), numpy.uint8)
>>> pygame.surfarray.make_surface(a)
<Surface(10x20x32 SW)>
>>> pygame.version.ver
'1.9.3'

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.