HGLRC CreateOpenGLDeviceContext() { PIXELFORMATDESCRIPTOR pfd = { 0 }; pfd.nSize = sizeof( PIXELFORMATDESCRIPTOR ); // just its size pfd.nVersion = 1; // always 1 pfd.dwFlags = PFD_SUPPORT_OPENGL | // OpenGL support - not DirectDraw PFD_DOUBLEBUFFER | // double buffering support PFD_DRAW_TO_WINDOW; // draw to the app window, not to a bitmap image pfd.iPixelType = PFD_TYPE_RGBA ; // red, green, blue, alpha for each pixel pfd.cColorBits = 24; // 24 bit == 8 bits for red, 8 for green, 8 for blue. // This count of color bits EXCLUDES alpha. pfd.cDepthBits = 32; // 32 bits to measure pixel depth. int pixelFormat = ChoosePixelFormat( GetDC( g_pHWND ), &pfd ); if ( pixelFormat == 0 ) { FatalAppExit( NULL, TEXT( "ChoosePixelFormat() failed!" ) ); } SetPixelFormat( GetDC( g_pHWND ), pixelFormat, &pfd ); HGLRC OpenGLContext = wglCreateContext( GetDC( g_pHWND ) ); wglMakeCurrent( GetDC( g_pHWND ), OpenGLContext ); RECT r; if ( GetClientRect( g_pHWND, &r ) ) { glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( r.left, r.right, r.bottom, r.top, -1.0, 1.0 ); glMatrixMode( GL_MODELVIEW ); glViewport( 0, 0, r.right - r.left, r.bottom - r.top ); } return OpenGLContext; }
void __cdecl _lockerr_exit ( char *msg ) { FatalAppExit(0, msg); /* Die with message box */ ExitProcess(255); /* Just die */ }
void FatalError(const char * ErrorText) { // This function outputs an error message and aborts the program. // Important: There is no universally portable way of outputting an // error message. You may have to modify this function to output // the error message in a way that is appropriate for your system. // Check if FatalAppExit exists (this macro is defined in winbase.h) #ifdef FatalAppExit // in Windows, use FatalAppExit: FatalAppExit(0, ErrorText); #else // in console mode, print error message printf ("\n%s\n", ErrorText); EndOfProgram(); #endif // Terminate program with error code exit(1); }
void WINAPI DbgBreakPoint(const CHAR *pCondition,const CHAR *pFileName,INT iLine) { if(g_fUseKASSERT) { DbgKernelAssert(pCondition, pFileName, iLine); } else { TCHAR szInfo[iDEBUGINFO]; wsprintf(szInfo, TEXT("%hs \nAt line %d of %hs\nContinue? (Cancel to debug)"), pCondition, iLine, pFileName); INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("Hard coded break point"), MB_SYSTEMMODAL | MB_ICONHAND | MB_YESNOCANCEL | MB_SETFOREGROUND); switch (MsgId) { case IDNO: /* Kill the application */ FatalAppExit(FALSE, TEXT("Application terminated")); break; case IDCANCEL: /* Break into the debugger */ DebugBreak(); break; case IDYES: /* Ignore break point continue execution */ break; } } }
bool ExtensionManager::isExtSupported( int ext ) { if( (*extensions) != ( NULL || "" ) ) { return( strchr( extensions, ext ) != NULL ? true : false ); } else { FatalAppExit( NULL, TEXT("Failed to load extensions.") ); return false; } }
void cmsSignalError(int ErrorCode, const char *ErrorText, ...) { va_list args; if (nDoAbort == LCMS_ERROR_IGNORE) return; va_start(args, ErrorText); if (UserErrorHandler != NULL) { char Buffer[1024]; vsnprintf(Buffer, 1023, ErrorText, args); va_end(args); if (UserErrorHandler(ErrorCode, Buffer)) { return; } } #if defined( __CONSOLE__ ) || defined( NON_WINDOWS ) fprintf(stderr, "lcms: Error #%d; ", ErrorCode); vfprintf(stderr, ErrorText, args); fprintf(stderr, "\n"); va_end(args); if (nDoAbort == LCMS_ERROR_ABORT) exit(1); #else { char Buffer1[1024]; char Buffer2[256]; snprintf(Buffer1, 767, "Error #%x; ", ErrorCode); vsnprintf(Buffer2, 255, ErrorText, args); strcat(Buffer1, Buffer2); MessageBox(NULL, Buffer1, "Little cms", MB_OK|MB_ICONSTOP|MB_TASKMODAL); va_end(args); if (nDoAbort == LCMS_ERROR_ABORT) { #ifdef __BORLANDC__ _cexit(); #endif FatalAppExit(0, "lcms is terminating application"); } } #endif }
HRESULT InitializeComponent(HWND hWnd) { RECT rect; HINSTANCE hInstance = GetModuleHandle(NULL); // Must be called to create the Trackbar InitCommonControls(); // Create the Panel GetClientRect(hWnd, &rect); g_hwndPanel = CreateWindowEx( 0, g_wc_panel.lpszClassName, "The title of my window", WS_CHILD | WS_VISIBLE | WS_BORDER, 0, rect.bottom - PANEL_H, rect.right /*w*/, PANEL_H/*h*/, hWnd, NULL, hInstance, NULL); if(g_hwndPanel == NULL) { MessageBox(NULL, "Window Creation Failed!", "Eror!", MB_ICONEXCLAMATION | MB_OK); return E_FAIL; } // Create the Play Button g_hwndButtonPlay = CreateWindowEx(0 , "BUTTON", NULL , WS_CHILD | WS_VISIBLE , rect.right/2 - BUTTON_W/2, BUTTON_BDR_DOWN + BUTTON_H, BUTTON_W, BUTTON_H , g_hwndPanel, (HMENU)ID_BUTTON_PLAY, hInstance, NULL); if(g_hwndButtonPlay == NULL) { MessageBox(NULL, "Play Button Creation Failed!", "Eror!", MB_ICONEXCLAMATION | MB_OK); return E_FAIL; } SetWindowText(g_hwndButtonPlay, "Play"); // Create Trackbar g_hwndTrackbar = CreateWindowEx(0, TRACKBAR_CLASS, // "TRACKBAR_CLASS" doesn't work NULL, WS_CHILD | WS_VISIBLE | TBS_HORZ, TRACKBAR_BDR_SIDE, TRACKBAR_BDR_UP, rect.right - TRACKBAR_BDR_SIDE*2, TRACKBAR_H, g_hwndPanel, (HMENU)ID_TRACKBAR, hInstance, NULL); if(g_hwndTrackbar == NULL) { CHAR errbuf[300]; wsprintf(errbuf, "Trackbar Creation Failed! Error code: #%d", GetLastError() ); FatalAppExit(-1, errbuf); } return S_OK; }
void ProcessThread::run() { try { processFile(); } catch(...) { fflush(stdout); fflush(stderr); fprintf(stderr, "\nGURU MEDITATION !!!\n"); FatalAppExit(0, L"Unhandeled exception error, application will exit!"); TerminateProcess(GetCurrentProcess(), -1); } }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int iCmdShow ) { TCHAR className[] = TEXT( "tray icon class" ); WM_TASKBARCREATED = RegisterWindowMessageA("TaskbarCreated") ; WNDCLASSEX wnd = { 0 }; wnd.hInstance = hInstance; wnd.lpszClassName = className; wnd.lpfnWndProc = WndProc; wnd.style = CS_HREDRAW | CS_VREDRAW ; wnd.cbSize = sizeof (WNDCLASSEX); wnd.hIcon = LoadIcon (NULL, IDI_APPLICATION); wnd.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wnd.hCursor = LoadCursor (NULL, IDC_ARROW); wnd.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE ; if (!RegisterClassEx(&wnd)) { FatalAppExit( 0, TEXT("Couldn't register window class!") ); } g_hwnd = CreateWindowEx(0, className, TEXT( "Using the system tray" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, hInstance, NULL); InitNotifyIconData(); Shell_NotifyIcon(NIM_ADD, &g_notifyIconData); ZeroMQContext::init(); Exit exit; MSG msg ; while (!quit) { PeekMessage(&msg, 0, 0, 0, PM_REMOVE); exit.receive_input(); TranslateMessage(&msg); DispatchMessage(&msg); } Shell_NotifyIcon(NIM_DELETE, &g_notifyIconData); return msg.wParam; }
void RAMObserverThread::run(void) { qDebug("RAM observer started!"); try { observe(); } catch(...) { fflush(stdout); fflush(stderr); fprintf(stderr, "\nGURU MEDITATION !!!\n"); FatalAppExit(0, L"Unhandeled exception error, application will exit!"); TerminateProcess(GetCurrentProcess(), -1); } while(m_semaphore.available()) m_semaphore.tryAcquire(); }
static void openStreams() { LPSTR outFile = strConcat(tmpDir, AXLOUT); LPSTR inFile = strConcat(tmpDir, AXLIN); LPSTR errFile = strConcat(tmpDir, AXLERR); win32out = fopen(outFile, "w+"); win32in = fopen(inFile, "r"); win32err = fopen(errFile, "w"); if (!win32out || !win32err) FatalAppExit(0, "Cannot open output streams..."); osSetStreams(win32in, win32out, win32err); stoFree(outFile); stoFree(inFile); stoFree(errFile); }
GLuint shadermanager::LoadFromFile( std::string& fpPath, std::string& vpPath ) { glShader fpShader; glShader vpShader; fpShader.Load( fpPath ); vpShader.Load( vpPath ); GLuint program = glCreateProgram(); glAttachShader( program, fpShader.GetObject() ); glAttachShader( program, vpShader.GetObject() ); glLinkProgram( program ); GLint success; glGetProgramiv( program, GL_LINK_STATUS, &success ); if( !success ) { GLint blen = 0; GLsizei slen = 0; glGetProgramiv( program, GL_INFO_LOG_LENGTH, &blen ); if( blen > 1 ) { char* log = (char*) malloc( blen ); char* log2 = "Linker error: "; glGetInfoLogARB( program, blen, &slen, log ); FatalAppExit( NULL, tools::DCharToError( log2, log ) ); free( log ); } } return program; }
CxContext* icxGetContext() { #ifdef CX_DLL #ifdef WIN32 CxContext* pContext = (CxContext*)TlsGetValue( g_TlsIndex ); if( !pContext ) { pContext = icxCreateContext(); if( !pContext ) { FatalAppExit( 0, "OpenCX. Problem to allocate memory for TLS OpenCX context." ); } TlsSetValue( g_TlsIndex, pContext ); } return pContext; #else CxContext* pContext = (CxContext*)pthread_getspecific( g_TlsIndex ); if( !pContext ) { pContext = icxCreateContext(); if( !pContext ) { fprintf(stderr,"OpenCX. Problem to allocate memory for OpenCX context."); exit(1); } pthread_setspecific( g_TlsIndex, pContext ); } return pContext; #endif #else /* CX_DLL */ static CxContext* pContext = 0; if( !pContext ) pContext = icxCreateContext(); return pContext; #endif }
//=--------------------------------------------------------------------------= // DisplayAssert //=--------------------------------------------------------------------------= // Display an assert message box with the given pszMsg, pszAssert, source // file name, and line number. The resulting message box has Abort, Retry, // Ignore buttons with Abort as the default. Abort does a FatalAppExit; // Retry does an int 3 then returns; Ignore just returns. // VOID DisplayAssert ( LPSTR pszMsg, LPSTR pszAssert, LPSTR pszFile, UINT line ) { char szMsg[250]; LPSTR lpszText; lpszText = pszMsg; // Assume no file & line # info // If C file assert, where you've got a file name and a line # // if (pszFile) { // Then format the assert nicely // wsprintf(szMsg, szFormat, (pszMsg&&*pszMsg) ? pszMsg : pszAssert, pszFile, line); lpszText = szMsg; } // Put up a dialog box // switch (_IdMsgBox(lpszText, szTitle, MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SYSTEMMODAL)) { case IDABORT: FatalAppExit(0, lpszText); return; case IDRETRY: // call the win32 api to break us. // DebugBreak(); return; } return; }
int Application::Run(HINSTANCE hInstance) const { HANDLE mutex = CreateMutex(nullptr, FALSE, _T("Selected text translate")); if (GetLastError() == ERROR_ALREADY_EXISTS) { FatalAppExit(0, TEXT("SelectedTextTranslate already started!")); } Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr); ServiceRegistry* serviceRegistry = ApplicationServiceRegistry::GetServiceRegistry(); Logger* logger = serviceRegistry->Get<Logger>(); logger->Log(LogLevels::Trace, L"Application start."); int result; try { ExceptionHelper::SetupStructuredExceptionsTranslation(); result = BootstrapApplication(serviceRegistry); delete serviceRegistry; } catch (...) { ExceptionHelper::TerminateOnException(logger); return -1; } ReleaseMutex(mutex); CloseHandle(mutex); Gdiplus::GdiplusShutdown(gdiplusToken); return result; }
void WINAPI DbgAssert(LPCTSTR pCondition,LPCTSTR pFileName,INT iLine) { if(g_fUseKASSERT) { DbgKernelAssert(pCondition, pFileName, iLine); } else { TCHAR szInfo[iDEBUGINFO]; (void)StringCchPrintf(szInfo, NUMELMS(szInfo),TEXT("%s \nAt line %d of %s\nContinue? (Cancel to debug)"), pCondition, iLine, pFileName); INT MsgId = MessageBoxOtherThread(NULL,szInfo,TEXT("ASSERT Failed"), MB_SYSTEMMODAL | MB_ICONHAND | MB_YESNOCANCEL | MB_SETFOREGROUND); switch (MsgId) { case IDNO: /* Kill the application */ FatalAppExit(FALSE, TEXT("Application terminated")); break; case IDCANCEL: /* Break into the debugger */ DebugBreak(); break; case IDYES: /* Ignore assertion continue execution */ break; } } }
/**************************************************************************** #ifdef DOCUMENTATION .MODULE errorPrintf .LIBRARY portable .TYPE función .DESCRIPTION imprime y hace exit(1) de un modo portable .SYSTEM DOS, UNIX .APPLICATION portable .ARGUMENTS int errorPrintf(char *mens,...) mens: formato printf ...: argumentos variables .NARRATIVE Sustituye a la funcion 'printf', permitiendo salidas por pantallas portables .RETURNS EOF si hay error número de bytes, en caso contrario .AUTHOR JMMM Juan M. Montero Martínez .LANGUAGE C .ENDOC END DOCUMENTATION #endif ****************************************************************************/ int errorPrintf(char *mens,...) { int auxiliar; va_list arg_ptr; va_start(arg_ptr, mens); auxiliar = vsprintf((char *) aux_str, mens, arg_ptr); va_end(arg_ptr); #if defined(__WIN32__) && defined(__CONSOLE__) int valor_tonto=__CONSOLE__; printf("CONSOLA %d\nERROR\n%s\nPulse retorno para continuar", valor_tonto,aux_str); OurBioskey(0); #elif defined(_Windows) // MessageBox(NULL, aux_str, "ERROR", /*MB_SYSTEMMODAL |*/ MB_OK); fcloseall(); FatalAppExit(0,aux_str); #else fprintf(stderr, "\nERROR\n%s\nPulse retorno para continuar", aux_str); OurBioskey(0); #endif fcloseall(); exit(1); return auxiliar; }
void ExceptionHelper::TerminateOnException(Logger* logger) { logger->LogFormatted(LogLevels::Fatal, L"Unhandled exception occurred.\n%ls", GetCurrentExceptionMessage().c_str()); FatalAppExit(0, L"Unhandled exception occurred. See logs for details."); }
void fatal(Exception* e, const char* fn) { FatalAppExit(1, fn); }
void __cdecl __security_init_cookie(void) { UINT_PTR cookie; FT systime = {0}; LARGE_INTEGER perfctr; #if defined (CHECK_FOR_LATE_COOKIE_INIT) PEXCEPTION_REGISTRATION_RECORD ehrec; #endif /* defined (CHECK_FOR_LATE_COOKIE_INIT) */ /* * Do nothing if the global cookie has already been initialized. On x86, * reinitialize the cookie if it has been previously initialized to a * value with the high word 0x0000. Some versions of Windows will init * the cookie in the loader, but using an older mechanism which forced the * high word to zero. */ if (__security_cookie != DEFAULT_SECURITY_COOKIE #if defined (_X86_) && (__security_cookie & 0xFFFF0000) != 0 #endif /* defined (_X86_) */ ) { __security_cookie_complement = ~__security_cookie; return; } #if defined (CHECK_FOR_LATE_COOKIE_INIT) /* * The security cookie is used to ensure the integrity of exception * handling. That means the cookie must be initialized in an image before * that image registers an exception handler that will use the cookie. We * attempt to detect this situation by checking if the calling thread has * already registered SEH handler _except_handler4. */ for (ehrec = (PEXCEPTION_REGISTRATION_RECORD)(UINT_PTR) __readfsdword(FIELD_OFFSET(NT_TIB, ExceptionList)); ehrec != EXCEPTION_CHAIN_END; ehrec = ehrec->Next) { if (ehrec->Handler == &_except_handler4) { /* * We've detected __except_handler4, alert the user by issuing * error R6035 and terminate the process. We use FatalAppExit * instead of _NMSG_WRITE because the loader lock may be held now, * and _NMSG_WRITE may do GetLibrary("user32.dll") for MessageBox, * which is unsafe under the loader lock. */ FatalAppExit(0, _RT_COOKIE_INIT_TXT); } if (ehrec >= ehrec->Next) { /* * Nodes in the exception record linked list are supposed to appear * at increasing addresses within the thread's stack. If the next * node is at a lower address, then the exception list is corrupted, * and we stop our check to avoid hitting a cycle in the list. */ break; } } #endif /* defined (CHECK_FOR_LATE_COOKIE_INIT) */ /* * Initialize the global cookie with an unpredictable value which is * different for each module in a process. Combine a number of sources * of randomness. */ GetSystemTimeAsFileTime(&systime.ft_struct); #if defined (_WIN64) cookie = systime.ft_scalar; #else /* defined (_WIN64) */ cookie = systime.ft_struct.dwLowDateTime; cookie ^= systime.ft_struct.dwHighDateTime; #endif /* defined (_WIN64) */ cookie ^= GetCurrentProcessId(); cookie ^= GetCurrentThreadId(); cookie ^= GetTickCount(); QueryPerformanceCounter(&perfctr); #if defined (_WIN64) cookie ^= perfctr.QuadPart; #else /* defined (_WIN64) */ cookie ^= perfctr.LowPart; cookie ^= perfctr.HighPart; #endif /* defined (_WIN64) */ #if defined (_WIN64) /* * On Win64, generate a cookie with the most significant word set to zero, * as a defense against buffer overruns involving null-terminated strings. * Don't do so on Win32, as it's more important to keep 32 bits of cookie. */ cookie &= 0x0000FFFFffffFFFFi64; #endif /* defined (_WIN64) */ /* * Make sure the cookie is initialized to a value that will prevent us from * reinitializing it if this routine is ever called twice. */ if (cookie == DEFAULT_SECURITY_COOKIE) { cookie = DEFAULT_SECURITY_COOKIE + 1; } #if defined (_X86_) else if ((cookie & 0xFFFF0000) == 0) { cookie |= cookie << 16; } #endif /* defined (_X86_) */ __security_cookie = cookie; __security_cookie_complement = ~cookie; }
LONG WINAPI UnhandledExceptionFilterEx(struct _EXCEPTION_POINTERS *pException){ CreateDumpFile(szMbsFile.c_str(), pException); // TODO: MiniDumpWriteDump FatalAppExit(-1, _T("Fatal Error")); return EXCEPTION_CONTINUE_SEARCH; }
void fatal(const Exception* e, const char_t* inFunction) throw() { if(e) FatalAppExit(-1, e->what()); else FatalAppExit(-1, _T("?")); }
LONG ApplicationCrashHandler(EXCEPTION_POINTERS *pException) { FatalAppExit(-1, _T("*** Unhandled Exception! ***")); return EXCEPTION_EXECUTE_HANDLER; }
CX_IMPL CXStatus cxGuiBoxReport( CXStatus status, const char *funcName, const char *context, const char *file, int line) { #ifdef WIN32 char mess[1000]; char title[100]; char *choice = 0; const char* errText = cxErrorStr( status ); if ( cxGetErrMode() != CX_ErrModeSilent ) { if( !funcName ) funcName = "<unknown>"; if( !context ) context = ""; if( !file ) file = ""; if( line < 0 ) line = 0; if( cxGetErrMode() == CX_ErrModeLeaf ) choice="\nErrMode=CX_ErrorModeLeaf\n" "\nTerminate the application?"; if( cxGetErrMode() == CX_ErrModeParent) choice="\nErrMode=CX_ErrorModeParent\n" "\nContinue?"; if( status == CX_StsBackTrace) wsprintf( mess,"Called from %s(): [file %s, line %d]\n%s\n%s\n(status:%d)\n%s", funcName, file,line,context, errText, status, choice); else if ( status == CX_StsAutoTrace ) wsprintf( mess,"Called from %s(): [file %s, line %d]\n%s\n%s\n(status:%d)\n%s", funcName, file, line, context, errText, status, choice); else wsprintf( mess,"In function %s(): [file %s, line %d]\n%s\n%s\n(status:%d)\n%s", funcName, file, line, context,errText, status, choice); wsprintf(title,"OpenCX Beta 2: %s",cxErrorStr(cxGetErrStatus())); int answer = -1; if( (( cxGetErrMode()==CX_ErrModeParent) && (IDCANCEL==MessageBox(NULL,mess,title,MB_ICONERROR|MB_OKCANCEL|MB_SYSTEMMODAL) ) || ((cxGetErrMode() == CX_ErrModeLeaf) && //(IDYES==MessageBox(NULL,mess,title,MB_ICONERROR|MB_YESNO|MB_SYSTEMMODAL)) (IDABORT == (answer=MessageBox(NULL,mess,title,MB_ICONERROR|MB_ABORTRETRYIGNORE|MB_SYSTEMMODAL))|| IDRETRY == answer) ))) { if( answer == IDRETRY ) { #if _MSC_VER >= 1200 || defined __ICL __asm int 3; #else assert(0); #endif } FatalAppExit(0,"OpenCX:\nterminating the application"); } }
void error(Exception* e, const char* fn) { FatalAppExit(0, e->what()); }
void __stdcall DolphinFatalExit(int /*exitCode*/, const char* msg) { FatalAppExit(0, msg); }