VOID TerminateOnAssert() { STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; STATIC_CONTRACT_DEBUG_ONLY; ShutdownLogging(); TerminateProcess(GetCurrentProcess(), 123456789); }
void error(const char* owner, const char* message, ...) { va_list ap; va_start(ap, message); vLog(FATAL, owner, message, LIGHT_RED, ap); va_end(ap); ShutdownLogging(); exit(1); }
int main(int argc, char* argv[]) { #ifdef M_TRIM_THRESHOLD // Prevent fragmentation of the heap by malloc (glibc). // // The default threshold is 128*1024, which can result in a large memory usage // due to fragmentation since we use a lot of small objects. On the other hand // if the threshold is too low, free() starts to permanently ask the kernel // about shrinking the heap. #ifdef HAVE_UNISTD_H int pagesize = sysconf(_SC_PAGESIZE); #else int pagesize = 4*1024; #endif mallopt(M_TRIM_THRESHOLD, 5*pagesize); #endif Interface::SanityCheck(VERSION_GEMRB); InitializeLogging(); core = new Interface( argc, argv ); if (core->Init() == GEM_ERROR) { delete( core ); print("Press enter to continue..."); textcolor(DEFAULT); getc(stdin); ShutdownLogging(); return -1; } #ifdef ANDROID #if SDL_COMPILEDVERSION < SDL_VERSIONNUM(1,3,0) SDL_ANDROID_SetApplicationPutToBackgroundCallback(&appPutToBackground, &appPutToForeground); #endif #endif core->Main(); delete( core ); textcolor(DEFAULT); ShutdownLogging(); return 0; }
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow) { g_hInstance = hInstance; json_value* appSettings = GetApplicationSettings(); if (GetApplicationSettingsError().length()) { std::string error = GetApplicationSettingsError(); error.append("\nApplication will terminate immediately. "); FatalError(NULL, error); } // Debugging options. bool show_console = (*appSettings)["debugging"]["show_console"]; bool subprocess_show_console = (*appSettings)["debugging"]["subprocess_show_console"]; std::string log_level = (*appSettings)["debugging"]["log_level"]; std::string log_file = (*appSettings)["debugging"]["log_file"]; log_file = GetAbsolutePath(log_file); // Initialize logging. if (std::wstring(lpstrCmdLine).find(L"--type=") != std::string::npos) { // This is a subprocess. InitializeLogging(subprocess_show_console, log_level, log_file); } else { // Main browser process. InitializeLogging(show_console, log_level, log_file); } // Command line arguments LPWSTR *argv; int argc; argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argv) { for (int i = 0; i < argc; i++) { std::string argument = WideToUtf8(std::wstring(argv[i])); size_t pos = argument.find("="); if (pos != std::string::npos) { std::string name = argument.substr(0, pos); std::string value = argument.substr(pos+1, std::string::npos); if (name == "--cgi-environment" && value.length()) { g_cgiEnvironmentFromArgv.assign(value); } } } } else { LOG_WARNING << "CommandLineToArgvW() failed"; } // CEF subprocesses. CefMainArgs main_args(hInstance); CefRefPtr<App> app(new App); int exit_code = CefExecuteProcess(main_args, app.get(), NULL); if (exit_code >= 0) { ShutdownLogging(); return exit_code; } LOG_INFO << "--------------------------------------------------------"; LOG_INFO << "Started application"; if (log_file.length()) LOG_INFO << "Logging to: " << log_file; else LOG_INFO << "No logging file set"; LOG_INFO << "Log level = " << FILELog::ToString(FILELog::ReportingLevel()); // Main window title option. std::string main_window_title = (*appSettings)["main_window"]["title"]; if (main_window_title.empty()) main_window_title = GetExecutableName(); // Single instance guid option. const char* single_instance_guid = (*appSettings)["application"]["single_instance_guid"]; if (single_instance_guid && single_instance_guid[0] != 0) { int guidSize = strlen(single_instance_guid) + 1; g_singleInstanceApplicationGuid = new wchar_t[guidSize]; Utf8ToWide(single_instance_guid, g_singleInstanceApplicationGuid, guidSize); } if (g_singleInstanceApplicationGuid && g_singleInstanceApplicationGuid[0] != 0) { g_singleInstanceApplication.Initialize( g_singleInstanceApplicationGuid); if (g_singleInstanceApplication.IsRunning()) { HWND hwnd = FindWindow(g_singleInstanceApplicationGuid, NULL); if (hwnd) { if (IsIconic(hwnd)) ShowWindow(hwnd, SW_RESTORE); SetForegroundWindow(hwnd); return 0; } } } // Window class name. if (g_singleInstanceApplicationGuid) { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", g_singleInstanceApplicationGuid); } else { swprintf_s(g_windowClassName, _countof(g_windowClassName), L"%s", Utf8ToWide(GetExecutableName()).c_str()); } if (!StartWebServer()) { FatalError(NULL, "Error while starting an internal local server.\n" "Application will terminate immediately."); } CefSettings cef_settings; // log_file std::string chrome_log_file = (*appSettings)["chrome"]["log_file"]; chrome_log_file = GetAbsolutePath(chrome_log_file); CefString(&cef_settings.log_file) = chrome_log_file; // log_severity std::string chrome_log_severity = (*appSettings)["chrome"]["log_severity"]; cef_log_severity_t log_severity = LOGSEVERITY_DEFAULT; if (chrome_log_severity == "verbose") { log_severity = LOGSEVERITY_VERBOSE; } else if (chrome_log_severity == "info") { log_severity = LOGSEVERITY_INFO; } else if (chrome_log_severity == "warning") { log_severity = LOGSEVERITY_WARNING; } else if (chrome_log_severity == "error") { log_severity = LOGSEVERITY_ERROR; } else if (chrome_log_severity == "error-report") { log_severity = LOGSEVERITY_ERROR_REPORT; } else if (chrome_log_severity == "disable") { log_severity = LOGSEVERITY_DISABLE; } cef_settings.log_severity = log_severity; // cache_path std::string cache_path = (*appSettings)["chrome"]["cache_path"]; cache_path = GetAbsolutePath(cache_path); CefString(&cef_settings.cache_path) = cache_path; // remote_debugging_port // A value of -1 will disable remote debugging. int remote_debugging_port = static_cast<long>( (*appSettings)["chrome"]["remote_debugging_port"]); if (remote_debugging_port == 0) { remote_debugging_port = random(49152, 65535+1); int i = 100; while (((i--) > 0) && remote_debugging_port == GetWebServerPort()) { remote_debugging_port = random(49152, 65535+1); } } if (remote_debugging_port > 0) { LOG_INFO << "remote_debugging_port = " << remote_debugging_port; cef_settings.remote_debugging_port = remote_debugging_port; } // Sandbox support cef_settings.no_sandbox = true; CefInitialize(main_args, cef_settings, app.get(), NULL); CreateMainWindow(hInstance, nCmdShow, main_window_title); CefRunMessageLoop(); CefShutdown(); LOG_INFO << "Ended application"; LOG_INFO << "--------------------------------------------------------"; ShutdownLogging(); return 0; }
VOID TerminateOnAssert() { ShutdownLogging(); TerminateProcess(GetCurrentProcess(), 123456789); }