0
votes

I'm working on some cross-platform code using OpenGL and SDL, but have immediately run into issues on Mac OSX.

For reference, here's the codebase on GitHub: https://github.com/GrooveStomp/platformer

I've also pushed the errors I'm seeing to that same repo: https://github.com/GrooveStomp/platformer/blob/master/errors.txt

Now, from the reading I've done, It seems as though SDL simply wraps around Mac OSX's Objective-C Cocoa layer and I need to declare my own NSAutoreleasePool to wrap my entire program. Is that correct?

I just came across this link: http://sourceforge.net/apps/wordpress/paintown/2010/12/26/sdl-and-osx/ in which the author installs from source and has no issues. I installed using Homebrew, which I assume is equivalent to the author's step #3, as I have to specify "-framework OpenGL" when building.

[EDIT]

So, it turns out that the NSAutoreleaseNoPool() issue should be taken care of by following these three steps:

  1. main() should have this signature: int main(int argc, char * argv[])
  2. #include <SDL.h> in the source file where main() is.
  3. link with -lSDLmain

The result is that SDL will wrap it's own main() with NSAutoreleasePool and all around my main. However, when I do this, I get the errors shown here:

https://github.com/GrooveStomp/platformer/blob/master/make_errors.txt

1
OSX Darwin 10.6.0, SDL 1.2.14GrooveStomp

1 Answers

1
votes

You get the message about memory "Just Leaking" when you send an Objective-C message on a thread without an NSAutoreleasePool in place. The problem with wrapping the whole program in the autorelease pool is it never gets drained and you risk running out of memory. Instead create the pool at the beginning of an event loop and drain at the end of each iteration. Doing this is the correct place should fix all of the "Just Leaking" errors.

Since NSAutorelasePool objects aren't normal objects, their proper use is a bit different from almost all other Cocoa objects. Here's a sample:


while(1)
{
    NSAutoreleasePool* pool = [NSAutoreleasePool new];

    // Do your event processing

    [pool drain];
}