diff options
Diffstat (limited to 'source/creator/creator.c')
-rw-r--r-- | source/creator/creator.c | 97 |
1 files changed, 46 insertions, 51 deletions
diff --git a/source/creator/creator.c b/source/creator/creator.c index 37fbf0cf76a..fbc97028d35 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -47,7 +47,7 @@ #include "BLI_threads.h" #include "BLI_utildefines.h" -/* mostly init functions */ +/* Mostly init functions. */ #include "BKE_appdir.h" #include "BKE_blender.h" #include "BKE_brush.h" @@ -69,10 +69,10 @@ #include "DEG_depsgraph.h" -#include "IMB_imbuf.h" /* for IMB_init */ +#include "IMB_imbuf.h" /* For #IMB_init. */ #include "RE_engine.h" -#include "RE_render_ext.h" +#include "RE_texture.h" #include "ED_datafiles.h" @@ -107,7 +107,7 @@ # include "sdlew.h" #endif -#include "creator_intern.h" /* own include */ +#include "creator_intern.h" /* Own include. */ /* Local Function prototypes. */ @@ -163,7 +163,7 @@ 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); + BLI_args_destroy(app_init_data->ba); app_init_data->ba = NULL; } @@ -244,7 +244,7 @@ int main(int argc, /* --- end declarations --- */ - /* ensure we free data on early-exit */ + /* Ensure we free data on early-exit. */ struct CreatorAtExitData app_init_data = {NULL}; BKE_blender_atexit_register(callback_main_atexit, &app_init_data); @@ -293,7 +293,7 @@ int main(int argc, MEM_use_guarded_allocator(); break; } - else if (STREQ(argv[i], "--")) { + if (STREQ(argv[i], "--")) { break; } } @@ -320,7 +320,7 @@ int main(int argc, sdlewInit(); #endif - /* Initialize logging */ + /* Initialize logging. */ CLG_init(); CLG_fatal_fn_set(callback_clg_fatal); @@ -349,7 +349,7 @@ int main(int argc, #if defined(__APPLE__) && !defined(WITH_PYTHON_MODULE) && !defined(WITH_HEADLESS) /* Patch to ignore argument finder gives us (PID?) */ - if (argc == 2 && STREQLEN(argv[1], "-psn_", 5)) { + if (argc == 2 && STRPREFIX(argv[1], "-psn_")) { extern int GHOST_HACK_getFirstFile(char buf[]); static char firstfilebuf[512]; @@ -366,7 +366,7 @@ int main(int argc, fpsetmask(0); #endif - /* initialize path to executable */ + /* Initialize path to executable. */ BKE_appdir_program_path_init(argv[0]); BLI_threadapi_init(); @@ -377,7 +377,6 @@ int main(int argc, BKE_blender_globals_init(); /* blender.c */ BKE_idtype_init(); - IMB_init(); BKE_cachefiles_init(); BKE_images_init(); BKE_modifier_init(); @@ -393,35 +392,53 @@ int main(int argc, /* First test for background-mode (#Global.background) */ #ifndef WITH_PYTHON_MODULE - ba = BLI_argsInit(argc, (const char **)argv); /* skip binary path */ + ba = BLI_args_create(argc, (const char **)argv); /* skip binary path */ /* Ensure we free on early exit. */ app_init_data.ba = ba; main_args_setup(C, ba); - BLI_argsParse(ba, 1, NULL, NULL); + /* Begin argument parsing, ignore leaks so arguments that call #exit + * (such as '--version' & '--help') don't report leaks. */ + MEM_use_memleak_detection(false); - main_signal_setup(); + /* Parse environment handling arguments. */ + BLI_args_parse(ba, ARG_PASS_ENVIRONMENT, NULL, NULL); #else /* Using preferences or user startup makes no sense for #WITH_PYTHON_MODULE. */ G.factory_startup = true; #endif + /* After parsing #ARG_PASS_ENVIRONMENT such as `--env-*`, + * since they impact `BKE_appdir` behavior. */ + BKE_appdir_init(); + /* After parsing number of threads argument. */ BLI_task_scheduler_init(); + /* Initialize sub-systems that use `BKE_appdir.h`. */ + IMB_init(); + +#ifndef WITH_PYTHON_MODULE + /* First test for background-mode (#Global.background) */ + BLI_args_parse(ba, ARG_PASS_SETTINGS, NULL, NULL); + + main_signal_setup(); +#endif + #ifdef WITH_FFMPEG + /* Keep after #ARG_PASS_SETTINGS since debug flags are checked. */ IMB_ffmpeg_init(); #endif - /* After level 1 arguments, this is so #WM_main_playanim skips #RNA_init. */ + /* After #ARG_PASS_SETTINGS arguments, this is so #WM_main_playanim skips #RNA_init. */ RNA_init(); RE_engines_init(); - init_nodesystem(); - psys_init_rng(); + BKE_node_system_init(); + BKE_particle_init_rng(); /* End second initialization. */ #if defined(WITH_PYTHON_MODULE) || defined(WITH_HEADLESS) @@ -442,38 +459,16 @@ int main(int argc, BKE_materials_init(); - if (G.background == 0) { #ifndef WITH_PYTHON_MODULE - BLI_argsParse(ba, 2, NULL, NULL); - BLI_argsParse(ba, 3, NULL, NULL); -#endif - WM_init(C, argc, (const char **)argv); - - /* This is properly initialized with user-preferences, - * but this is default. - * Call after loading the #BLENDER_STARTUP_FILE so we can read #U.tempdir */ - BKE_tempdir_init(U.tempdir); + if (G.background == 0) { + BLI_args_parse(ba, ARG_PASS_SETTINGS_GUI, NULL, NULL); } - else { -#ifndef WITH_PYTHON_MODULE - BLI_argsParse(ba, 3, NULL, NULL); + BLI_args_parse(ba, ARG_PASS_SETTINGS_FORCE, NULL, NULL); #endif - WM_init(C, argc, (const char **)argv); + WM_init(C, argc, (const char **)argv); - /* Don't use user preferences #U.tempdir */ - BKE_tempdir_init(NULL); - } -#ifdef WITH_PYTHON - /** - * \note the #U.pythondir string is NULL until #WM_init() is executed, - * so we provide the BPY_ function below to append the user defined - * python-dir to Python's `sys.path` at this point. Simply putting - * #WM_init() before #BPY_python_start() crashes Blender at startup. - */ - - /* TODO: #U.pythondir */ -#else +#ifndef WITH_PYTHON printf( "\n* WARNING * - Blender compiled without Python!\n" "this is not intended for typical usage\n\n"); @@ -490,6 +485,7 @@ int main(int argc, /* OK we are ready for it */ #ifndef WITH_PYTHON_MODULE + /* Handles #ARG_PASS_FINAL. */ main_args_setup_post(C, ba); #endif @@ -500,6 +496,9 @@ int main(int argc, callback_main_atexit(&app_init_data); BKE_blender_atexit_unregister(callback_main_atexit, &app_init_data); + /* End argument parsing, allow memory leaks to be printed. */ + MEM_use_memleak_detection(true); + /* Paranoid, avoid accidental re-use. */ #ifndef WITH_PYTHON_MODULE ba = NULL; @@ -511,11 +510,7 @@ int main(int argc, (void)argv; #endif -#ifdef WITH_PYTHON_MODULE - /* Keep blender in background-mode running. */ - return 0; -#endif - +#ifndef WITH_PYTHON_MODULE if (G.background) { /* Using window-manager API in background-mode is a bit odd, but works fine. */ WM_exit(C); @@ -524,9 +519,9 @@ int main(int argc, if (!G.file_loaded) { WM_init_splash(C); } + WM_main(C); } - - WM_main(C); +#endif /* WITH_PYTHON_MODULE */ return 0; } /* End of int main(...) function. */ |