[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] I'm having problems with the pygame C api



Ben Smith wrote:

> Sure, that makes sense in relation to the broken c program.  However, 
> the Actual Code(tm) has pygame (and pymousetrap) imported from a 
> python script, before I call the PySurface_Check function in my C module.  
> So, I should be imported for this function in that case, right?  I still 
> get a false value for PySurface_Check in that case, though the object sure
> looks like a pysurface in my debugger.


the best place to call the "import_pygame_surface" function is
inside your "initmodule()" function that gets called when python
initializes your module. be sure to call it _after_ the module
has initialized itself. if you look at any of the pygame modules,
you can easily see how these import macros are used.

the different pygame modules don't get any "special benefits"
that a module you write doesn't get. so the stuff that pygame.draw
does to get surface objects and work with them is no different than
what you can do in your own extensions.

since the PySurface_Check() is failing, i'm pretty sure the problem is 
that you haven't yet "import_pygame_surface()"d. your "PySurface_Type" 
is likely pointing to NULL.



> Yeah, I'm aware of the ref counting issues, though I didn't remember 
> to implement it for this little proggie.  pymousetrap doesn't leak 
> like that ;)


heh, i kind of figured :] those little test programs are always full of 
holes.



>>another quick warning.. one thing never tested is initializing some 
>>parts of SDL through the SDL functions and then using them through 
>>pygame. 

>
> Good point.  Didn't think about that.


i wouldn't worry about this too much, i little knowledge about how SDL 
works should keep you from doing anything foolish :] on the other hand, 
don't be too surprised if you find something that does break.

 
> Thank you. I still have the question of why PySurface_Check is failing 
> when both modules are imported from a python script. 


just remember, it's not important that your python code imports both 
modules. your extension module must call the pygame_import_surface() 
macro for it's C calls to pygame to work.




____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org