Crash using NSAutoreleasePool with SDL 1.2.14 on Mac OS X

OS: Mac OS X 10.6.6
SDL: 1.2.14

Currently I am developing an application that uses SDL in a multi-threaded environment. For this purpose, I use performSelectorOnMainThread() to run all the SDL functions in the main thread, however I’m stuck with crashes. Trying to reproduce this problem in a simple application, it turns out that I already get crash at exit when I created an NSAutoreleasePool and released it. I haven’t tried SDL 1.3 because migrating to 1.3 is not an option right now.

I know that the pool is unnecessary in this case but it’s necessary in my original application and it shouldn’t cause any harm either. I may be missing something simple so any help is appreciated. Thanks in advance.

File: testoverlay_m.m
Adapted from testoverlay.c with minor modification (only 3 lines of modification, to create and release NSAutoreleasePool). Here’s the diff:
15d14
< #import <Foundation/Foundation.h>
324d322
< NSAutoreleasePool *apool = [[NSAutoreleasePool alloc]init];
594d591
< [apool drain];-------------

  1. line 15: #import <Foundation/Foundation.h>
  2. line 324 right after main(): NSAutoreleasePool *apool = [[NSAutoreleasePool alloc]init];
  3. line 594 right before return(0): [apool drain];

Compilation command:
gcc -o testoverlay_m testoverlay_m.m -I/usr/local/include/SDL -L/usr/local/lib -lSDLmain -lSDL -Wl,-framework,Cocoa -g

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000000000001e
0x00007fff80fe411c in objc_msgSend ()

#0 0x00007fff80fe411c in objc_msgSend ()
#1 0x00007fff87026fe0 in -[NSCGSContext _invalidate] ()
#2 0x00007fff87026f64 in -[NSCGSContext dealloc] ()
#3 0x00007fff87026f45 in -[NSWindowGraphicsContext dealloc] ()
#4 0x00007fff84d051e6 in _CFAutoreleasePoolPop ()
#5 0x00007fff82aa4100 in -[NSAutoreleasePool drain] ()
#6 0x0000000100002726 in SDL_main (argc=1, argv=0x100111ce0) at testoverlay_m.m:594
#7 0x0000000100002930 in -[SDLMain applicationDidFinishLaunching:] (self=<value temporarily unavailable, due to optimizations>, _cmd=<value temporarily unavailable, due to optimizations>, note=<value temporarily unavailable, due to optimizations>) at ./src/main/macosx/SDLMain.m:300

.