src/SDL_log.c
changeset 7710 6364d6836634
parent 7614 af0bd07212bd
child 7727 627ce8499c81
equal deleted inserted replaced
7709:edd2c14acf66 7710:6364d6836634
   330         if (consoleAttached == 0) {
   330         if (consoleAttached == 0) {
   331             attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
   331             attachResult = AttachConsole(ATTACH_PARENT_PROCESS);
   332             if (!attachResult) {
   332             if (!attachResult) {
   333                     attachError = GetLastError();
   333                     attachError = GetLastError();
   334                     if (attachError == ERROR_INVALID_HANDLE) {
   334                     if (attachError == ERROR_INVALID_HANDLE) {
   335                         OutputDebugString(TEXT("Parent process has no console"));
   335                         OutputDebugString(TEXT("Parent process has no console\r\n"));
   336                         consoleAttached = -1;
   336                         consoleAttached = -1;
   337                     } else if (attachError == ERROR_GEN_FAILURE) {
   337                     } else if (attachError == ERROR_GEN_FAILURE) {
   338                          OutputDebugString(TEXT("Could not attach to console of parent process"));
   338                          OutputDebugString(TEXT("Could not attach to console of parent process\r\n"));
   339                          consoleAttached = -1;
   339                          consoleAttached = -1;
   340                     } else if (attachError == ERROR_ACCESS_DENIED) {  
   340                     } else if (attachError == ERROR_ACCESS_DENIED) {  
   341                          /* Already attached */
   341                          /* Already attached */
   342                         consoleAttached = 1;
   342                         consoleAttached = 1;
   343                     } else {
   343                     } else {
   344                         OutputDebugString(TEXT("Error attaching console"));
   344                         OutputDebugString(TEXT("Error attaching console\r\n"));
   345                         consoleAttached = -1;
   345                         consoleAttached = -1;
   346                     }
   346                     }
   347                 } else {
   347                 } else {
   348                     /* Newly attached */
   348                     /* Newly attached */
   349                     consoleAttached = 1;
   349                     consoleAttached = 1;
   352                 if (consoleAttached == 1) {
   352                 if (consoleAttached == 1) {
   353                         stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
   353                         stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
   354                 }
   354                 }
   355         }
   355         }
   356 
   356 
   357         length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1;
   357         length = SDL_strlen(SDL_priority_prefixes[priority]) + 2 + SDL_strlen(message) + 1 + 1 + 1;
   358         output = SDL_stack_alloc(char, length);
   358         output = SDL_stack_alloc(char, length);
   359         SDL_snprintf(output, length, "%s: %s\n", SDL_priority_prefixes[priority], message);
   359         SDL_snprintf(output, length, "%s: %s\r\n", SDL_priority_prefixes[priority], message);
   360         tstr = WIN_UTF8ToString(output);
   360         tstr = WIN_UTF8ToString(output);
   361         
   361         
   362         /* Output to debugger */
   362         /* Output to debugger */
   363         OutputDebugString(tstr);
   363         OutputDebugString(tstr);
   364        
   364        
   365         /* Screen output to stderr, if console was attached. */
   365         /* Screen output to stderr, if console was attached. */
   366         if (consoleAttached == 1) {
   366         if (consoleAttached == 1) {
   367                 if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
   367                 if (!WriteConsole(stderrHandle, tstr, lstrlen(tstr), &charsWritten, NULL)) {
   368                     OutputDebugString(TEXT("Error calling WriteConsole"));
   368                     OutputDebugString(TEXT("Error calling WriteConsole\r\n"));
   369                 }
   369                 }
   370                 if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) {
   370                 if (charsWritten == ERROR_NOT_ENOUGH_MEMORY) {
   371                     OutputDebugString(TEXT("Insufficient heap memory to write message"));
   371                     OutputDebugString(TEXT("Insufficient heap memory to write message\r\n"));
   372                 }
   372                 }
   373         }
   373         }
   374 
   374 
   375         SDL_free(tstr);
   375         SDL_free(tstr);
   376         SDL_stack_free(output);
   376         SDL_stack_free(output);