diff options
author | Thomas White <taw27@cam.ac.uk> | 2008-11-24 21:55:42 +0000 |
---|---|---|
committer | Thomas White <taw27@cam.ac.uk> | 2008-11-24 21:55:42 +0000 |
commit | 7cff5dfde008101ea789ca07b2d2114273f84d0d (patch) | |
tree | 2d9aae6d2cf372ade89028b1cfe0c15b518346ef /src/main.c | |
parent | 6d00b2ed8e122ef493f32292e4500f73b113b2a1 (diff) |
Much cleaner exit
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -32,6 +32,7 @@ #include <stdio.h> #include <glib.h> #include <SDL.h> +#include <unistd.h> #include "types.h" #include "mainwindow.h" @@ -40,29 +41,37 @@ int main(int argc, char *argv[]) { MainWindow *mw; + int graphics = 0; GThread *accel_thread; - - gtk_init(&argc, &argv); + int finished = 0; + g_thread_init(NULL); + if ( gtk_init_check(&argc, &argv) ) { + graphics = 1; + } + if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) { fprintf(stderr, "Couldn't initialise SDL: %s\n", SDL_GetError()); return 1; } - atexit(SDL_Quit); /* Start the accelerometer thread */ - accel_thread = accelerometer_start(); - - /* Open the window */ - mw = mainwindow_open(); + accel_thread = accelerometer_start(&finished); - /* Wait "forever" */ - if ( mw != NULL ) { + if ( graphics ) { + /* Open the window */ + mw = mainwindow_open(); gtk_main(); + } else { + while ( 1 ) { + sleep(10); + } } + finished = 1; g_thread_join(accel_thread); + SDL_Quit(); return 0; |