SDL 1.3 (rev 5019), MacOSX 10.5.8 and threading

Hi everyone :slight_smile:

I’m new to Mac OS X and SDL programming, and I’ve been asked to port an existing Unix/Windows program (with SDL support) to Mac OS X.

However I cannot get a correct frame for my window when SDL_Init() and SDL_SetVideoMode() are called outside the main thread. Here is a sample code to reproduce the problem:

Code:
#include <SDL.h>

int test_thread(void *data)
{
int done = 0;
SDL_Init (SDL_INIT_VIDEO);
SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_RESIZABLE);
while (!done) {
SDL_Event event;
SDL_GL_SwapBuffers();
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) done = 1;
}
}
return 0;
}

int main(int argc, char* argv[])
{
if (1) {
/DOES NOT WORK/
SDL_Thread *thread1 = SDL_CreateThread(test_thread, NULL);
SDL_WaitThread(thread1, NULL);
} else {
/WORKS/
test_thread(NULL);
}
SDL_Quit();
return 0;
}

I’m using Mac OS X 10.5.8 and SDL 1.3.0-5019.

Have you ever seen this problem? Am I doing sth wrong? Do you know what it is due to?
I have no choice for my port: SDL_Init() needs to be called from a separate thread.

I forgot to mention the command-line:
gcc -o test test.c -g -O2 -I/usr/local/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE -I/usr/X11/include -DHAVE_OPENGL -L/usr/local/lib -lSDL

[Wink] [Arrow]

Initializing graphics and handling events are unlikely to work from a
thread other than the main one; this isn’t an SDL limitation, it’s a
"feature" of a number of popular platforms (Windows in particular).

If you want your app to work, you’ll need to rearrange things so the
main thread is handling everything to do with graphics and input.On 09-10-16 9:20 AM, rbouqueau wrote:

I’m new to Mac OS X and SDL programming, and I’ve been asked to port
an existing Unix/Windows program (with SDL support) to Mac OS X.

However I cannot get a correct frame for my window when SDL_Init() and
SDL_SetVideoMode() are called outside the main thread. Here is a
sample code to reproduce the problem:


Chris Herborth (@Chris_Herborth) – http://www.pobox.com/~chrish/
Marooned, the survival game! – http://marooned-game.livejournal.com/
Never send a monster to do the work of an evil scientist.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: chrish.vcf
Type: text/x-vcard
Size: 386 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20091016/83844c15/attachment.vcf

I’m sorry to insist, but I’m totally stuck and I don’t know what is being done wrong (and where).

After reading that Cocoa could be put into multithreaded mode, I created a simple function which launches a thread; IsMultiThreaded returns true, but I still get the same incorrect frame around my window…

Thanks to anybody who will help me: a complete example + command line is included in my previous messages so that it can be reproduced quickly :slight_smile: