src/SDL.c
changeset 1190 173c063d4f55
parent 769 b8d311d90021
child 1312 c9b51268668f
     1.1 --- a/src/SDL.c	Wed Nov 23 07:23:48 2005 +0000
     1.2 +++ b/src/SDL.c	Wed Nov 23 07:29:56 2005 +0000
     1.3 @@ -220,15 +220,25 @@
     1.4  void SDL_Quit(void)
     1.5  {
     1.6  	/* Quit all subsystems */
     1.7 +#ifdef DEBUG_BUILD
     1.8 +  printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); fflush(stdout);
     1.9 +#endif
    1.10  	SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
    1.11  
    1.12  #ifdef CHECK_LEAKS
    1.13 +#ifdef DEBUG_BUILD
    1.14 +  printf("[SDL_Quit] : CHECK_LEAKS\n"); fflush(stdout);
    1.15 +#endif
    1.16 +
    1.17  	/* Print the number of surfaces not freed */
    1.18  	if ( surfaces_allocated != 0 ) {
    1.19  		fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n", 
    1.20  							surfaces_allocated);
    1.21  	}
    1.22  #endif
    1.23 +#ifdef DEBUG_BUILD
    1.24 +  printf("[SDL_Quit] : SDL_UninstallParachute()\n"); fflush(stdout);
    1.25 +#endif
    1.26  
    1.27  	/* Uninstall any parachute signal handlers */
    1.28  	SDL_UninstallParachute();
    1.29 @@ -236,6 +246,10 @@
    1.30  #if !defined(DISABLE_THREADS) && defined(ENABLE_PTH)
    1.31  	pth_kill();
    1.32  #endif
    1.33 +#ifdef DEBUG_BUILD
    1.34 +  printf("[SDL_Quit] : Returning!\n"); fflush(stdout);
    1.35 +#endif
    1.36 +
    1.37  }
    1.38  
    1.39  /* Return the library version number */
    1.40 @@ -244,6 +258,7 @@
    1.41  	return(&version);
    1.42  }
    1.43  
    1.44 +#ifndef __OS2__
    1.45  #if defined(_WIN32_WCE) || (defined(__WATCOMC__) && defined(BUILD_DLL))
    1.46  /* Need to include DllMain() on Windows CE and Watcom C for some reason.. */
    1.47  #include <windows.h>
    1.48 @@ -262,3 +277,75 @@
    1.49  	return TRUE;
    1.50  }
    1.51  #endif /* _WIN32_WCE and building DLL with Watcom C */
    1.52 +#else
    1.53 +// Building for OS/2
    1.54 +#ifdef __WATCOMC__
    1.55 +
    1.56 +#define INCL_DOSERRORS
    1.57 +#define INCL_DOSEXCEPTIONS
    1.58 +#include <os2.h>
    1.59 +
    1.60 +// Exception handler to prevent the Audio thread hanging, making a zombie process!
    1.61 +ULONG _System SDL_Main_ExceptionHandler(PEXCEPTIONREPORTRECORD pERepRec,
    1.62 +                                        PEXCEPTIONREGISTRATIONRECORD pERegRec,
    1.63 +                                        PCONTEXTRECORD pCtxRec,
    1.64 +                                        PVOID p)
    1.65 +{
    1.66 +  if (pERepRec->fHandlerFlags & EH_EXIT_UNWIND)
    1.67 +    return XCPT_CONTINUE_SEARCH;
    1.68 +  if (pERepRec->fHandlerFlags & EH_UNWINDING)
    1.69 +    return XCPT_CONTINUE_SEARCH;
    1.70 +  if (pERepRec->fHandlerFlags & EH_NESTED_CALL)
    1.71 +    return XCPT_CONTINUE_SEARCH;
    1.72 +
    1.73 +  // Do cleanup at every fatal exception!
    1.74 +  if (((pERepRec->ExceptionNum & XCPT_SEVERITY_CODE) == XCPT_FATAL_EXCEPTION) &&
    1.75 +      (pERepRec->ExceptionNum != XCPT_BREAKPOINT) &&
    1.76 +      (pERepRec->ExceptionNum != XCPT_SINGLE_STEP)
    1.77 +     )
    1.78 +  {
    1.79 +    if (SDL_initialized & SDL_INIT_AUDIO)
    1.80 +    {
    1.81 +      // This removes the zombie audio thread in case of emergency.
    1.82 +#ifdef DEBUG_BUILD
    1.83 +      printf("[SDL_Main_ExceptionHandler] : Calling SDL_CloseAudio()!\n");
    1.84 +#endif
    1.85 +      SDL_CloseAudio();
    1.86 +    }
    1.87 +  }
    1.88 +  return (XCPT_CONTINUE_SEARCH);
    1.89 +}
    1.90 +
    1.91 +
    1.92 +EXCEPTIONREGISTRATIONRECORD SDL_Main_xcpthand = {0, SDL_Main_ExceptionHandler};
    1.93 +
    1.94 +// The main DLL entry for DLL Initialization and Uninitialization:
    1.95 +unsigned _System LibMain(unsigned hmod, unsigned termination)
    1.96 +{
    1.97 +  if (termination)
    1.98 +  {
    1.99 +#ifdef DEBUG_BUILD
   1.100 +//    printf("[SDL DLL Unintialization] : Removing exception handler\n");
   1.101 +#endif
   1.102 +    DosUnsetExceptionHandler(&SDL_Main_xcpthand);
   1.103 +    return 1;
   1.104 +  } else
   1.105 +  {
   1.106 +#ifdef DEBUG_BUILD
   1.107 +    // Make stdout and stderr unbuffered!
   1.108 +    setbuf(stdout, NULL);
   1.109 +    setbuf(stderr, NULL);
   1.110 +#endif
   1.111 +    // Fire up exception handler
   1.112 +#ifdef DEBUG_BUILD
   1.113 +//    printf("[SDL DLL Initialization] : Setting exception handler\n");
   1.114 +#endif
   1.115 +    // Set exception handler
   1.116 +    DosSetExceptionHandler(&SDL_Main_xcpthand);
   1.117 +
   1.118 +    return 1;
   1.119 +  }
   1.120 +}
   1.121 +
   1.122 +#endif
   1.123 +#endif