[SDL] RE: Problem porting a python module that calls SDL on MacOS
Cesare @ Poetic Studios
cesare at poeticstudios.com
Mon Mar 14 01:13:12 PST 2005
Bob Ippolito wrote:
> On Mar 13, 2005, at 8:28, Cesare wrote:
>>>> /Recently I've converted a SDL/OpenGL app with python embedded to a
>>> />/python library.
>>>> /Under MacOS X I get hundreds of NSAutoreleaseNoPool errors when the c
>>> />/code calls SDL_Init_Video.
>>> />/The problem, I believe, is that under MacOS X SDL is implemented
>>> />/Cocoa. It expects that I run an application with a main(). But in my
>>> />/case the main loop is in the python script, which call
>>> />/and everything else in a function inside the c extension.
>>> Can you not call the initialization that is in SDLmain.m normally in
>>> from your library?
>> I've tried it. but I can't figure out how to call objective c code
>> from c code.
>> Also, I want to keep the compilation easy (I use python distutils to
>> make the module).
>> I've partially solved calling NSApplicationLoad() before creating the
>> Now I get some leaks as before but the app works, even if I can't
>> receive keyboard events in
>> windowed mode.
>> It seems to me that I can't stick to plain c in the macosx code, like
>> I did for win and linux version.
>> Maybe there's a plain c api to just initializa Cocoa, disable what I
>> guess is a kind of obj-c garbage
>> collection, and give focus to the sdl event manager in my window?
> Check out pygame CVS and look at the source. It does this all
> correctly, from pure Python code no less (via PyObjC), I'm not sure
> why you didn't listen to me the first time. I'm also not sure why
> you're writing another python binding for SDL instead of just
> extending pygame. The relevant module is, unsurprisingly, pygame.macosx.
> As far as calling Objective-C code from C code, you can't. You can't
> call C++ code from C code either. The solution to either is similar,
> write a C function in the Objective-C module, and link to it.
> Distutils understands well enough that .m files should get compiled by
> GCC, so linking in SDLmain.m or something like it wouldn't cause any
> SDL mailing list
> SDL at libsdl.org
I did listen to you. :)
I didn't want to add another library dependence (PyObjC). I want my
module to be easy to complile and use.
I know that there's already PyOpenGL, and that it can work upon PyGame.
But I need something different for my purpose.
I'm trying to do for python what proce55ing (www.processing.org) is for
java. A simplified environment for teching and playing with graphic
I also want the source code to be as clear and tweakable as possible.
Current version (www.cesaremarilungo.com/blog/devachan.htm) works
flawlessly on Windows and Linux. It used to work flawlessly on MacOS X
when wrapped with SDLmain.m as an app.
OK. I'll try to investingate in this direction.
More information about the SDL