BOOL My_FatalExit() { int ExitCode=NULL; DWORD error_Real = 0; DWORD error_Intercepted = 0; __try{ disableInterception(); FatalExit (ExitCode); error_Real = GetLastError(); enableInterception(); FatalExit (ExitCode); error_Intercepted = GetLastError(); }__except(puts("in filter"), 1){puts("exception caught");} return (error_Real == error_Intercepted); }
void NewTrap(char *name) { int rc; char buf[128]; sprintf(buf, "Unimplemented API: %s\n\nPress OK to continue execution,\npress Cancel to quit application", name); rc = MessageBox((HWND)NULL, buf, "Trap", MB_ICONEXCLAMATION | MB_OKCANCEL); if ( rc == IDCANCEL ) FatalExit(0); }
void golgotha_app::init() { sw32 i; for (i=0; i<(int)argc; i++) { if (argv[i] == "-max_memory") { i++; i4_const_str::iterator p(argv[i].begin()); _max_memory = (w32)p.read_number(); } } char buf[300]; #ifdef _WINDOWS LoadString(i4_win32_instance,IDS_INITIALISATION,buf,300); #else printf("Starting initialisation sequence\n"); strcpy(buf,"Initialisation, please wait..."); #endif i4_status_class * status=i4_create_status(buf,0); status->update(0.01f); r1_truncate_texture_file(); i4_file_class * inittest=i4_open("resource.res",I4_READ|I4_NO_BUFFER); if (!inittest) { //i4_error("_FATAL: resource.res not found in the current directory. " // "Check that the current directory is the directory the exe-file " // "resides in."); #ifdef _WINDOWS MessageBox(0,"FATAL: resource.res not found in the current directory. " "Check that the current directory is the directory the exe-file " "resides in.","Golgotha: Wrong startup directory",0); #else printf("FATAL: resource.res not found in the current directory. \n" "Check that the current directory is the directory the executable file \n" "resides in."); #endif exit(89); } delete inittest; memory_init(); //calls init__init::i4_init() to init all i4_init_classes status->update(0.1f); i4_endianesstest end; end.anint=0x0ff; #pragma warning (disable:4127) // Conditional expression is constant if (end.chars[0]==0xff) { i4_warning("Detected architecture is little endian."); if (i4_litend!=1) { i4_error("FATAL: Golgotha was compiled for a big-endian system. " "Please rebuild Golgotha with the correct endianness setting in arch.h"); exit(92); } } else { i4_warning("Detected architecture is big endian."); if (i4_litend!=0) { i4_error("FATAL: Golgotha was compiled for a little-endian system. " "Please rebuild Golgotha with the correct endianness setting in arch.h"); exit(92); } } #pragma warning(1:4127) i4_warning("Loading resource Manager..."); resource_init("resource.res",0); strcpy(first_level, "test.level"); //Hardcoded first level li_add_function("set_default_level", g1_set_default_level); i4_warning("Executing scheme/start.scm"); li_load("scheme/start.scm"); i4_mkdir("savegame"); //create the savegame directory if it doesn't exist #ifdef _WINDOWS CheckDXVersion(); #endif status->update(0.2f); display_init(); status->update(0.23f); printf("Display initialisation ok.\n"); i4_image_class * im=i4_load_image("bitmaps/comic1.jpg"); printf("If this line is drawn, the jpg loader is ok.\n"); status->update(0.25f); #ifdef _WINDOWS cwnd.Attach(current_window_handle); g1_sound_man.poll(i4_T); // update sound effects (play next narative sfx) do_poll_sound_man=i4_T; i4_add_thread((i4_thread_func_type)Thread_Sound_Man_Poller,1000,NULL); g1_sound_man.loop_current_song=i4_T; #else //All sound is currently disabled under linux and the thread synchronization //code isn't complete either do_poll_sound_man=i4_F; g1_sound_man.loop_current_song=i4_F; #endif //wm is the window-manager wm->set_background_color(0); if (im) //Im is the Cartoon image { loading_window=new i4_image_window_class(im, i4_T, i4_F); wm->add_child(wm->width()/2-loading_window->width()/2, wm->height()/2-loading_window->height()/2, loading_window.get()); } refresh(); // show something right away status->update(0.3f); char * font_fname=li_get_string(li_get_value("font"),0); i4_image_class * fim=i4_load_image(font_fname); if (!fim) { i4_error("image load failed : %s", font_fname); } i4_current_app->get_style()->font_hint->normal_font=new i4_anti_proportional_font_class(fim); delete fim; status->update(0.4f); choice_first_level(); //Attempt to initialize a rendering api suitable for the current display. g1_render.r_api = r1_create_api(display); i4_warning("Render api created successfully: %s.",g1_render.r_api->name()); refresh(); status->update(0.5f); //init the renderer! if (!g1_render.r_api) { /* MessageBox(NULL,"Could not initialize a rendering device. \n" "Possible Causes:\n-You tried to run the game in a window " "with your desktop color depth not equal to 16Bit.\n" "-There's not enough video memory available for this mode.\n" "-Your DirectX installation is invalid.\n" "-Well, err...","DirectX initialisation failed", MB_OK+MB_ICONSTOP+MB_APPLMODAL);*/ #ifdef _WINDOWS char * s=(char *)malloc(1000); LoadString(AfxGetResourceHandle(),IDS_RENDERINITFAILED,s,999); MessageBox(NULL,s,"DirectX",MB_OK+MB_ICONSTOP+MB_APPLMODAL); free(s); FatalExit(99); #else printf("FATAL ERROR: Initialisation of renderer failed. Quitting.\n"); exit(99); #endif } g1_input.init(); g1_resources.load(); li_load("scheme/preferences.scm"); status->update(0.6f); i4_bool movie_time = i4_F; for (i=0; i<(int)argc; i++) { if (argv[i] == i4gets("movie_option")) { movie_time = i4_T; } } if (g1_render.r_api->get_render_device_flags() & R1_SOFTWARE) { //setup a timer and decide whether or not to do double pixel //default is high res mode int processor_speed = i4_get_clocks_per_second(); g1_resources.render_window_expand_mode = R1_COPY_1x1; /* if (processor_speed > 170000000) g1_resources.render_window_expand_mode = R1_COPY_1x1; else if (processor_speed > 140000000) g1_resources.render_window_expand_mode = R1_COPY_1x1_SCANLINE_SKIP; else g1_resources.render_window_expand_mode = R1_COPY_2x2; g1_resources.radius_mode = g1_resource_class::VIEW_LOW; */ if (movie_time) { g1_resources.radius_mode = g1_resource_class::VIEW_FAR; } } else { //hardware rasterizer, view distance = far by default g1_resources.radius_mode = g1_resource_class::VIEW_FAR; } s1_load(); g1_load_images(); status->update(0.7f); g1_player_man.init_colors(&display->get_screen()->get_pal()->source, g1_render.r_api); protocol=i4_get_first_protocol(); i4_graphical_style_class * style=wm->get_style(); /* style->color_hint->button.active.bright=(135<<8)|64; style->color_hint->button.active.medium=(114<<8)|49; style->color_hint->button.active.dark=(88<<8)|38; style->color_hint->button.passive.bright=(120<<8)|64; style->color_hint->button.passive.medium=(100<<8)|49; style->color_hint->button.passive.dark=(70<<8)|38; */ if (!g1_cwin_man) { g1_cwin_man=new g1_cwin_man_class; } status->update(0.8f); g1_cwin_man->init(wm, style, display->get_screen(), display, wm); if (m1_maxtool_man) { m1_maxtool_man->init(wm,style,display->get_screen(),display,wm); } li_add_function("Pause", g1_pause); li_add_function("ForcePause", g1_force_pause); li_add_function("is_paused",g1_is_paused); status->update(1.0f); hide_main_menu(); main_menu=new g1_help_screen_class(wm->width(), wm->height(), wm->get_style(), i4gets("startup_screen"), G1_PLOT_SCREEN); wm->add_child(0,0,main_menu); delete status; status=0; i4_kernel.request_events(this, i4_device_class::FLAG_DO_COMMAND | i4_device_class::FLAG_END_COMMAND| i4_device_class::FLAG_DISPLAY_CHANGE); do_main_menu(); if (start_in_editor) { g1_cwin_man->set_edit_mode(i4_T); } //start game with startup screens //if (!movie_time) //{ // help_screen("startup_screen", G1_START_HELP_SCREEN); //} //else //{ // start_new_game(); //} }
int main( int argc, char **argv ) { #ifdef __APPLE__ string macDir = get_mac_dir(); string configFile = macDir + "/../configuration.ini"; #else string configFile = "configuration.ini"; #endif load_configuration(configFile); SDL_Surface *surface; SDL_Event event; int videoFlags; videoFlags = SDL_OPENGL; // Enable OpenGL in SDL videoFlags |= SDL_GL_DOUBLEBUFFER; // Enable double buffering //videoFlags |= SDL_HWPALETTE; // Store the palette in hardware if ( displayFullscreen ) videoFlags |= SDL_FULLSCREEN; if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) ); //Quit( 1 ); } if (hardwareCursor) SDL_ShowCursor(SDL_DISABLE); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); surface = SDL_SetVideoMode( displayWidth, displayHeight, displayBpp, videoFlags ); SDL_WM_SetCaption("Torque Tracer","icon"); bindKeys(); OpenGL_init(); #ifdef __APPLE__ string fontPath = macDir + "/Contents/Resources/Vera.ttf"; const char *fontFile = strdup(fontPath.c_str()); #else const char *fontFile = "Vera.ttf"; #endif load_font(fontFile, &font[0], 18); ////////////////////////////////////// // torque curve initial points - for debugging /*torqueCurve.push_back( vector2fSet(-0.7, -0.7) ); torqueCurve.push_back( vector2fSet(-0.7 + incrementX * 1, -0.7 + incrementY*2) ); torqueCurve.push_back( vector2fSet(-0.7 + incrementX * 2, -0.7 + incrementY*3) );*/ bool exitApplication = false; while ( true ) { if (exitApplication == true) break; SDL_PollEvent( &event ); SDL_PumpEvents(); sdl_mouseUpdate(); if (event.type == SDL_QUIT) exitApplication = true; //////////////////////////////////////////// // check keyboard keys unsigned char *keyState = (unsigned char *) SDL_GetKeyState(NULL); for ( unsigned int klv=0 ; klv<BUTTONS_KEYBOARD ; klv++) { if ( keyState[klv] && keyboardButtons[klv].pressedLf == false ) { keyboardButtons[klv].pressedLf = true; if (keyboardButtons[klv].action == ACTION_QUIT) exitApplication = true; if (keyboardButtons[klv].action == ACTION_TOGGLE_MODE) { if (inputMode == INPUT_MODE_RESIZE) inputMode = INPUT_MODE_DRAW; else if (inputMode == INPUT_MODE_DRAW) inputMode = INPUT_MODE_ENTER_TEXT; else if (inputMode == INPUT_MODE_ENTER_TEXT) inputMode = INPUT_MODE_RESIZE; //printf("toggle mode\n"); } if (keyboardButtons[klv].action == ACTION_TORQUE_ZOOM_IN) { if (incrementY < 6) incrementY *= 1.25; } if (keyboardButtons[klv].action == ACTION_TORQUE_ZOOM_OUT) { if (incrementY > 0.05) incrementY /= 1.25; } if (keyboardButtons[klv].action == ACTION_WRITE_FILE) { writeTorqueCurve(); } if (keyboardButtons[klv].action == ACTION_TOGGLE_TORQUE_UNITS) { if (torqueMode == TORQUEMODE_METRIC) torqueMode = TORQUEMODE_IMPERIAL; else torqueMode = TORQUEMODE_METRIC; } if (inputMode == INPUT_MODE_ENTER_TEXT) { // this covers numbers if ( SDLK_0 <= klv && klv <= SDLK_9 ) enteredText += klv ; if ( klv == SDLK_PERIOD) enteredText += "."; if ( klv == SDLK_n ) enteredText += "Nm @"; if ( klv == SDLK_f ) enteredText += "ft-lbs @"; if ( klv == SDLK_k ) enteredText += "kW @"; if ( klv == SDLK_h || klv == SDLK_b ) enteredText += "bhp @"; if ( klv == SDLK_BACKSPACE ) { // if you're backspacing over an @ sign, just clear the whole string to start over if (enteredText[enteredText.size()-1] == '@') enteredText.resize(0); if ( enteredText.size() > 0) enteredText.resize(enteredText.size()-1); } if ( klv == SDLK_RETURN ) { processEnteredText(); } } } else if (!keyState[klv] && keyboardButtons[klv].pressedLf == true) { keyboardButtons[klv].pressedLf = false; } } /////////////////////////////////////// // check mouse stuff for (unsigned int mlv=0 ; mlv<BUTTONS_MOUSE ; mlv++) { if ( inputMode == INPUT_MODE_DRAW) { if (mouseButtons[mlv].pressed && mouseButtons[mlv].pressedLf == false) { if ( mlv == 1) // left click { // no negative values please if (mousePos.a[0] > gridStartX && mousePos.a[1] > gridStartY) { insertPointInCurve(mousePos); } } else if ( mlv == 3) // right click { // erase on right-click ////////////////////////////////////////////// // this works //if (torqueCurve.size() > 0) // torqueCurve.pop_back(); ////////////////////////////////////////////// // but we should probably erase whatever were closest to if ( torqueCurve.size() == 0) { break; } if ( torqueCurve.size() == 1) { torqueCurve.pop_back(); } if (closestPointToMouse == torqueCurve.size()-1) { torqueCurve.pop_back(); break; } vector<c_vector2f>::iterator it; unsigned int index = 0; for ( it=torqueCurve.begin() ; it<torqueCurve.end()-1 ; it++ ) { if (index == closestPointToMouse) { torqueCurve.erase(it,it+1); break; } index++; } } } } else if (inputMode == INPUT_MODE_RESIZE) { if ( mouseButtons[mlv].pressed) // left click or right click { if ( (mousePos.a[0] > pictureL-0.1) && (mousePos.a[0] < pictureL+0.1) ) { pictureL = mousePos.a[0]; //printf("l-border\n"); } if ( (mousePos.a[0] > pictureR-0.1) && (mousePos.a[0] < pictureR+0.1) ) { pictureR = mousePos.a[0]; //printf("r-border\n"); } if ( (mousePos.a[1] > pictureT-0.1) && (mousePos.a[1] < pictureT+0.1) ) { pictureT = mousePos.a[1]; //printf("t-border\n"); } if ( (mousePos.a[1] > pictureB-0.1) && (mousePos.a[1] < pictureB+0.1) ) { pictureB = mousePos.a[1]; //printf("b-border\n"); } } } } // debug text for (unsigned int l=0 ; l<torqueCurve.size() ; l++ ) { //printf("(%f,%f)\n", torqueCurve[l].a[0], torqueCurve[l].a[1]); } //printf("\n"); OpenGL_render(); SDL_GL_SwapBuffers(); } printf("done.\n"); // reset resolution SDL_Quit(); ///////////////////////////////////// // every generation of windows gets // progressively lamer. xp requires // this to exit cleanly. // C'est la micro$oft #ifdef WIN32 FatalExit(666); #endif return 0; }
extern "C" void _assert() { FatalAppExitW(0, L"assertion failed"); FatalExit(0); }
extern "C" int __cdecl _purecall() { FatalAppExitW(0, L"pure virtual call"); FatalExit(0); return 0; }
void os::fatalExit(int num) { FatalExit(num); }
void NEAR PASCAL DrvInit(void) { HANDLE hlibUser; LPDRIVERTABLE lpdt; /* If the window's driver interface is present then use it. */ DOUT("MMSYSTEM: DrvInit"); hlibUser = GetModuleHandle(szUser); if(lpOpenDriver = (OPENDRIVER31)GetProcAddress(hlibUser,szOpenDriver)) fUseWinAPI = TRUE; else { fUseWinAPI = FALSE; DOUT(" - No Windows Driver I/F detected. Using MMSYSTEM\r\n"); // // force MMSYSTEM into the driver table, without enableing it. // cInstalledDrivers = 1; hInstalledDriverList = GlobalAlloc(GHND|GMEM_SHARE, (DWORD)((WORD)sizeof(DRIVERTABLE))); #ifdef DEBUG if (hInstalledDriverList == NULL) { DOUT("no memory for driver table\r\n"); FatalExit(-1); return; } #endif lpdt = (LPDRIVERTABLE)GlobalLock(hInstalledDriverList); // // NOTE! we are not setting fFirstEntry==TRUE // // because under windows 3.0 MMSOUND will enable/disable us // we *dont* wan't the driver interface doing it! // lpdt->lpDriverEntryPoint = (DRIVERPROC)DriverProc; lpdt->hModule = ghInst; lpdt->fFirstEntry = 0; GlobalUnlock(hInstalledDriverList); } if (fUseWinAPI) { DOUT(" - Windows Driver I/F detected\r\n"); #ifdef DEBUG if (GetWinVer() < 0x30A) DOUT("MMSYSTEM: WARNING !!! WINDOWS DRIVER I/F BUT VERSION LESS THAN 3.1\r\n"); #endif // link to the relevant user APIs. lpCloseDriver = (CLOSEDRIVER31)GetProcAddress(hlibUser, szCloseDriver); lpGetDriverModuleHandle = (GETDRIVERMODULEHANDLE31)GetProcAddress(hlibUser, szDrvModuleHandle); lpSendDriverMessage = (SENDDRIVERMESSAGE31)GetProcAddress(hlibUser, szSendDriverMessage); lpDefDriverProc = (DEFDRIVERPROC31)GetProcAddress(hlibUser, szDefDriverProc); } }
void __stdcall DolphinFatalExit(int exitCode, const char* msg) { int result = fprintf(stderr, "%s\n", msg); FatalExit(exitCode); }
sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage) { char const * env = getenv( "SAL_DIAGNOSE_ABORT" ); #if defined(_DEBUG) && !defined(NO_DEBUG_CRT) _CrtDbgReport(_CRT_ASSERT, pszFileName, nLine, NULL, pszMessage); return ( ( env != NULL ) && ( *env != '\0' ) ); #else HWND hWndParent; UINT nFlags; int nCode; /* get app name or NULL if unknown (don't call assert) */ LPCSTR lpszAppName = "Error"; sal_Char szMessage[512]; /* format message into buffer */ szMessage[sizeof(szMessage)-1] = '\0'; /* zero terminate always */ _snprintf(szMessage, sizeof(szMessage)-1, "%s: File %hs, Line %d\n:%s\n", lpszAppName, pszFileName, nLine, pszMessage); OutputDebugString(szMessage); if ( _pPrintDetailedDebugMessage ) _pPrintDetailedDebugMessage( pszFileName, nLine, pszMessage ); else if ( _pPrintDebugMessage ) _pPrintDebugMessage( szMessage ); else { if ( !getenv( "DISABLE_SAL_DBGBOX" ) ) { TCHAR szBoxMessage[1024]; /* active popup window for the current thread */ hWndParent = GetActiveWindow(); if (hWndParent != NULL) hWndParent = GetLastActivePopup(hWndParent); /* set message box flags */ nFlags = MB_TASKMODAL | MB_ICONWARNING | MB_YESNOCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND; if (hWndParent == NULL) nFlags |= MB_SERVICE_NOTIFICATION; /* display the assert */ szBoxMessage[sizeof(szBoxMessage)-1] = 0; _snprintf(szBoxMessage, sizeof(szBoxMessage)-1, "%s\n( Yes=Abort / No=Ignore / Cancel=Debugger )", szMessage); nCode = MessageBox(hWndParent, szBoxMessage, "Assertion Failed!", nFlags); if (nCode == IDYES) FatalExit(-1); if (nCode == IDNO) return sal_False; /* ignore */ if (nCode == IDCANCEL) return sal_True; /* will cause oslDebugBreak */ } else { fputs(szMessage, stderr); // fall back } return ( ( env != NULL ) && ( *env != '\0' ) ); } return sal_False; #endif /* _DEBUG && !NO_DEBUG_CRT */ }