Changeset View
Changeset View
Standalone View
Standalone View
source/creator/creator.c
| Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void main_callback_setup(void) | static void main_callback_setup(void) | ||||
| { | { | ||||
| /* Error output from the alloc routines: */ | /* Error output from the alloc routines: */ | ||||
| MEM_set_error_callback(callback_mem_error); | MEM_set_error_callback(callback_mem_error); | ||||
| } | } | ||||
| /* free data on early exit (if Python calls 'sys.exit()' while parsing args for eg). */ | |||||
| struct CreatorAtExitData { | |||||
| bArgs *ba; | |||||
| #ifdef WIN32 | |||||
| const char **argv; | |||||
| int argv_num; | |||||
| #endif | |||||
| }; | |||||
| static void callback_main_atexit(void *user_data) | |||||
| { | |||||
| struct CreatorAtExitData *app_init_data = user_data; | |||||
| if (app_init_data->ba) { | |||||
| BLI_argsFree(app_init_data->ba); | |||||
| app_init_data->ba = NULL; | |||||
| } | |||||
| #ifdef WIN32 | |||||
| if (app_init_data->argv) { | |||||
| while (app_init_data->argv_num) { | |||||
| free(app_init_data.argv[--app_init_data->argv_num]); | |||||
| } | |||||
| free(app_init_data->argv); | |||||
| app_init_data->argv = NULL; | |||||
| } | |||||
| #endif | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Main Function | /** \name Main Function | ||||
| * \{ */ | * \{ */ | ||||
| Show All 35 Lines | |||||
| #ifdef WIN32 | #ifdef WIN32 | ||||
| char **argv; | char **argv; | ||||
| int argv_num; | int argv_num; | ||||
| #endif | #endif | ||||
| /* --- end declarations --- */ | /* --- end declarations --- */ | ||||
| /* ensure we free data on early-exit */ | |||||
| struct CreatorAtExitData app_init_data = {NULL}; | |||||
| BKE_blender_atexit_register(callback_main_atexit, &app_init_data); | |||||
| #ifdef WIN32 | #ifdef WIN32 | ||||
| /* We delay loading of openmp so we can set the policy here. */ | /* We delay loading of openmp so we can set the policy here. */ | ||||
| # if defined(_MSC_VER) | # if defined(_MSC_VER) | ||||
| _putenv_s("OMP_WAIT_POLICY", "PASSIVE"); | _putenv_s("OMP_WAIT_POLICY", "PASSIVE"); | ||||
| # endif | # endif | ||||
| /* FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it. */ | /* FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it. */ | ||||
| # if defined(_MSC_VER) && defined(_M_X64) | # if defined(_MSC_VER) && defined(_M_X64) | ||||
| _set_FMA3_enable(0); | _set_FMA3_enable(0); | ||||
| # endif | # endif | ||||
| /* Win32 Unicode Args */ | /* Win32 Unicode Args */ | ||||
| /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialized | /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialized | ||||
| * (it depends on the args passed in, which is what we're getting here!) | * (it depends on the args passed in, which is what we're getting here!) | ||||
| */ | */ | ||||
| { | { | ||||
| wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); | wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); | ||||
| argv = malloc(argc * sizeof(char *)); | argv = malloc(argc * sizeof(char *)); | ||||
| for (argv_num = 0; argv_num < argc; argv_num++) { | for (argv_num = 0; argv_num < argc; argv_num++) { | ||||
| argv[argv_num] = alloc_utf_8_from_16(argv_16[argv_num], 0); | argv[argv_num] = alloc_utf_8_from_16(argv_16[argv_num], 0); | ||||
| } | } | ||||
| LocalFree(argv_16); | LocalFree(argv_16); | ||||
| /* free on early-exit */ | |||||
| app_init_data.argv = argv; | |||||
| app_init_data.argv_num = argv_num; | |||||
| } | } | ||||
| #endif /* WIN32 */ | #endif /* WIN32 */ | ||||
| /* NOTE: Special exception for guarded allocator type switch: | /* NOTE: Special exception for guarded allocator type switch: | ||||
| * we need to perform switch from lock-free to fully | * we need to perform switch from lock-free to fully | ||||
| * guarded allocator before any allocation happened. | * guarded allocator before any allocation happened. | ||||
| */ | */ | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | #ifdef WITH_GAMEENGINE | ||||
| syshandle = SYS_GetSystem(); | syshandle = SYS_GetSystem(); | ||||
| #else | #else | ||||
| syshandle = 0; | syshandle = 0; | ||||
| #endif | #endif | ||||
| /* first test for background */ | /* first test for background */ | ||||
| #ifndef WITH_PYTHON_MODULE | #ifndef WITH_PYTHON_MODULE | ||||
| ba = BLI_argsInit(argc, (const char **)argv); /* skip binary path */ | ba = BLI_argsInit(argc, (const char **)argv); /* skip binary path */ | ||||
| /* ensure we free on early exit */ | |||||
| app_init_data.ba = ba; | |||||
| main_args_setup(C, ba, &syshandle); | main_args_setup(C, ba, &syshandle); | ||||
| BLI_argsParse(ba, 1, NULL, NULL); | BLI_argsParse(ba, 1, NULL, NULL); | ||||
| main_signal_setup(); | main_signal_setup(); | ||||
| #else | #else | ||||
| G.factory_startup = true; /* using preferences or user startup makes no sense for py-as-module */ | G.factory_startup = true; /* using preferences or user startup makes no sense for py-as-module */ | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | #ifndef WITH_PYTHON_MODULE | ||||
| if (G.background == 0) { | if (G.background == 0) { | ||||
| if (!G.file_loaded) | if (!G.file_loaded) | ||||
| if (U.uiflag2 & USER_KEEP_SESSION) | if (U.uiflag2 & USER_KEEP_SESSION) | ||||
| WM_recover_last_session(C, NULL); | WM_recover_last_session(C, NULL); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Explicitly free data allocated for argument parsing: | |||||
| * - 'ba' | |||||
| * - 'argv' on WIN32. | |||||
| */ | |||||
| callback_main_atexit(&app_init_data); | |||||
| BKE_blender_atexit_unregister(callback_main_atexit, &app_init_data); | |||||
| /* paranoid, avoid accidental re-use */ | |||||
| #ifndef WITH_PYTHON_MODULE | #ifndef WITH_PYTHON_MODULE | ||||
| BLI_argsFree(ba); | ba = NULL; | ||||
| (void)ba; | |||||
| #endif | #endif | ||||
| #ifdef WIN32 | #ifdef WIN32 | ||||
| while (argv_num) { | |||||
| free(argv[--argv_num]); | |||||
| } | |||||
| free(argv); | |||||
| argv = NULL; | argv = NULL; | ||||
| (void)argv; | |||||
| #endif | #endif | ||||
| #ifdef WITH_PYTHON_MODULE | #ifdef WITH_PYTHON_MODULE | ||||
| return 0; /* keep blender in background mode running */ | return 0; /* keep blender in background mode running */ | ||||
| #endif | #endif | ||||
| if (G.background) { | if (G.background) { | ||||
| /* Using window-manager API in background mode is a bit odd, but works fine. */ | /* Using window-manager API in background mode is a bit odd, but works fine. */ | ||||
| Show All 36 Lines | |||||