test/testerror.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
equal deleted inserted replaced
7638:783d1cff9b20 7639:9406b7dd2f2d
    34 {
    34 {
    35     /* Set the child thread error string */
    35     /* Set the child thread error string */
    36     SDL_SetError("Thread %s (%lu) had a problem: %s",
    36     SDL_SetError("Thread %s (%lu) had a problem: %s",
    37                  (char *) data, SDL_ThreadID(), "nevermind");
    37                  (char *) data, SDL_ThreadID(), "nevermind");
    38     while (alive) {
    38     while (alive) {
    39         printf("Thread '%s' is alive!\n", (char *) data);
    39         SDL_Log("Thread '%s' is alive!\n", (char *) data);
    40         SDL_Delay(1 * 1000);
    40         SDL_Delay(1 * 1000);
    41     }
    41     }
    42     printf("Child thread error string: %s\n", SDL_GetError());
    42     SDL_Log("Child thread error string: %s\n", SDL_GetError());
    43     return (0);
    43     return (0);
    44 }
    44 }
    45 
    45 
    46 int
    46 int
    47 main(int argc, char *argv[])
    47 main(int argc, char *argv[])
    48 {
    48 {
    49     SDL_Thread *thread;
    49     SDL_Thread *thread;
    50 
    50 
       
    51     /* Enable standard application logging */
       
    52     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
       
    53 
    51     /* Load the SDL library */
    54     /* Load the SDL library */
    52     if (SDL_Init(0) < 0) {
    55     if (SDL_Init(0) < 0) {
    53         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    56         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    54         return (1);
    57         return (1);
    55     }
    58     }
    56 
    59 
    57     /* Set the error value for the main thread */
    60     /* Set the error value for the main thread */
    58     SDL_SetError("No worries");
    61     SDL_SetError("No worries");
    59 
    62 
    60     alive = 1;
    63     alive = 1;
    61     thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
    64     thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
    62     if (thread == NULL) {
    65     if (thread == NULL) {
    63         fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    66         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
    64         quit(1);
    67         quit(1);
    65     }
    68     }
    66     SDL_Delay(5 * 1000);
    69     SDL_Delay(5 * 1000);
    67     printf("Waiting for thread #1\n");
    70     SDL_Log("Waiting for thread #1\n");
    68     alive = 0;
    71     alive = 0;
    69     SDL_WaitThread(thread, NULL);
    72     SDL_WaitThread(thread, NULL);
    70 
    73 
    71     printf("Main thread error string: %s\n", SDL_GetError());
    74     SDL_Log("Main thread error string: %s\n", SDL_GetError());
    72 
    75 
    73     SDL_Quit();
    76     SDL_Quit();
    74     return (0);
    77     return (0);
    75 }
    78 }