Properly loading cocoa applications as modules
Properly loading cocoa applications as modules
- Subject: Properly loading cocoa applications as modules
- From: Zachary Drew <email@hidden>
- Date: Fri, 7 Jan 2005 15:58:36 -0600
I'm porting a modular video rendering framework[1] to OS X and I'm
having trouble getting some dynamically loaded Cocoa code to properly
initialize. The framework itself is written in C99 and the module I'm
trying to load uses SDL to display video. The SDL library for OS X is
itself written in Cocoa. In order to stay application agnostic, the
Cocoa code needs to stay within the module I'm trying to load. Here is
what I've done:
-I converted the module loading code to use NSLinkModule and compiled
the modules as bundles. This appears to be totally functional.
-The application uses posix threads. Upon calling the module's
initialization routine, I create a dummy NSThread which immediately
exits. For each posix thread, I create an NSAutoRelease Pool. This
cleared warnings about memory leaks. The NSThread isMultiThreaded
routine correctly indicates the application is in multithreaded mode.
At this point, attempting to run the application died with this error:
*** Uncaught exception: <NSInternalInconsistencyException> Error (1002)
creating CGSWindow
I traced this error to the Cocoa being uninitialized.
What I am unclear about is exactly how I initialize Cocoa properly from
the module's initialization routine. I.e., procedurally without an
Info.plist and without a main nib file. I tried inserting this into the
module's initialization routine
[NSApplication sharedApplication];
if(NSApplicationLoad())
fprintf(stderr, "loading cocoa\n");
Now a window comes up, but the application dies on a bus error. Here is
the gdb backtrace of the bus error:
Program received signal EXC_BAD_ACCESS, Could not access memory.
[Switching to process 9931 thread 0xb803]
0x94da3a64 in QDFlushPortBuffer ()
(gdb) bt
#0 0x94da3a64 in QDFlushPortBuffer ()
#1 0x0102536c in QZ_UpdateRects (this=0x183b000, numRects=1,
rects=0xf02b4be0) at SDL_QuartzVideo.m:1473
#2 0x0102e4dc in SDL_UpdateRect (screen=0x22002442, x=17131580,
y=3656272, w=3247664, h=3440032) at SDL_video.c:1004
#3 0x0102e8b4 in SDL_Flip (screen=0x0) at SDL_video.c:1117
#4 0x0102da44 in SDL_SetVideoMode (width=768, height=576, bpp=32,
flags=1) at SDL_video.c:704
#5 0x000301ec in consumer_play_video (this=0xffffffff,
frame=0xffffffff) at consumer_sdl.c:451
#6 0x00030d98 in video_thread (arg=0x4a000) at consumer_sdl.c:623
#7 0x900246e8 in _pthread_body ()
I'm not entirely sure that this is caused by improper Cocoa
initialization but this is my best guess. Can someone give me some
hints on how to correctly load the Cocoa runtime procedurally from a
dynamically loaded bundle?
Thanks for any help,
-Zach
P.S. the code has always worked when SDL is used in full-screen mode,
which I assumes bypasses the NSApplication stuff
[1] http://mlt.sf.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden