[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] BUG: PixelArray



Lenard Lindstrom wrote:
Marcus von Appen wrote:
On, Sat Aug 25, 2007, Lenard Lindstrom wrote:

[lambda errors]

Which SVN version do you exactly have? It should not happen in rev
1045ff. However, did you delete your (outdated) Setup file after
the latest checkout, so it will be regenerated from Setup.in? Make sure,
Setup contains the following lines:

[...]
mask src/mask.c src/bitmask.c $(SDL) $(DEBUG)
pixelarray src/pixelarray.c $(SDL) $(DEBUG)
[...]

The error you described is a typical "module not installed and thus not
found" issue, thus I guess, your Setup is broken.


The module didn't compile. I am building for Python 2.5 using gcc 3.4.5 under MinGW. This is the error message I got:

src/pixelarray.c:176: error: initializer element is not constant
src/pixelarray.c:176: error: (near initialization for `PyPixelArray_Type.tp_getattro')

This is the location in the code:

static PyTypeObject PyPixelArray_Type =
{
   PyObject_HEAD_INIT(NULL)
....
   PyObject_GenericGetAttr,    /* tp_getattro */  <---

I have seen this before. PyObject_GenericGetAttr is an imported function, so not a constant. Such slot assignments must be done in the module's init function.

P.S. Here is a patch. It now passes the tests. There is another patch for the pixelarray.py example which removes the assumption that the display is 32 bit.

P.P.S. Should PixelArray work with 24 bit surfaces?

>>> import pygame
>>> pygame.init()
(6, 0)
>>> s = pygame.Surface((100, 100), 0, 24)
>>> s.fill((255, 0, 0))
<rect(0, 0, 100, 100)>
>>> a = pygame.PixelArray(s)
>>> hex(a[0][0])
'0xff0000'
>>> a[0][0] = 0xff
>>> del a
>>> s.get_at((0, 0))
(255, 0, 0, 255)

--
Lenard Lindstrom
<len-l@xxxxxxxxx>

*** pixelarray.c	Fri Aug 24 16:42:42 2007
--- ../trunk/src/pixelarray.c	Sat Aug 25 10:21:22 2007
***************
*** 173,179 ****
      0,                          /* tp_hash */
      0,                          /* tp_call */
      0,                          /* tp_str */
!     PyObject_GenericGetAttr,    /* tp_getattro */
      0,                          /* tp_setattro */
      &_pxarray_as_buffer,        /* tp_as_buffer */
      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS,
--- 173,179 ----
      0,                          /* tp_hash */
      0,                          /* tp_call */
      0,                          /* tp_str */
!     0,                          /* tp_getattro */
      0,                          /* tp_setattro */
      &_pxarray_as_buffer,        /* tp_as_buffer */
      Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS,
***************
*** 1260,1265 ****
--- 1260,1266 ----
      
      /* create the module */
      module = Py_InitModule3 ("pixelarray", NULL, NULL);
+     PyPixelArray_Type.tp_getattr = PyObject_GenericGetAttr;
      Py_INCREF (&PyPixelArray_Type);
      PyModule_AddObject (module, "PixelArray", (PyObject *) &PyPixelArray_Type);
      
*** pixelarray.py	Sat Aug 25 10:32:24 2007
--- ../trunk/examples/pixelarray.py	Sat Aug 25 10:42:36 2007
***************
*** 7,13 ****
  screen = pygame.display.set_mode ((400, 400))
  screen.fill ((100, 100, 100))
  
! sf = pygame.Surface ((50, 50))
  
  sf.fill ((0,0,0))
  rect = sf.get_rect ()
--- 7,13 ----
  screen = pygame.display.set_mode ((400, 400))
  screen.fill ((100, 100, 100))
  
! sf = pygame.Surface ((50, 50), 0, 32)
  
  sf.fill ((0,0,0))
  rect = sf.get_rect ()