Cleanup: simplify order of initialization with argument parsing

Sub-systems that use directories from BKE_appdir needed to be
initialized after parsing '--env-system-datafiles'.

This meant the animation player needed to call IMB_init it's self.

Avoid this complication by having a pass that can be used to setup
the environment before Blender's resources are accessed.

This reverts the workaround from 9ea345d1cf
This commit is contained in:
Campbell Barton
2020-10-27 18:21:16 +11:00
parent eebe274312
commit 09139e41ed
2 changed files with 37 additions and 26 deletions

View File

@@ -403,25 +403,30 @@ int main(int argc,
* (such as '--version' & '--help') don't report leaks. */ * (such as '--version' & '--help') don't report leaks. */
MEM_use_memleak_detection(false); MEM_use_memleak_detection(false);
BLI_argsParse(ba, 1, NULL, NULL); /* Parse environment handling arguments. */
BLI_argsParse(ba, 0, NULL, NULL);
main_signal_setup();
#else #else
/* Using preferences or user startup makes no sense for #WITH_PYTHON_MODULE. */ /* Using preferences or user startup makes no sense for #WITH_PYTHON_MODULE. */
G.factory_startup = true; G.factory_startup = true;
#endif #endif
/* After parsing the first level of arguments as `--env-*` impact BKE_appdir behavior. */ /* After parsing '0' level args such as `--env-*`, since they impact `BKE_appdir` behavior. */
BKE_appdir_init(); BKE_appdir_init();
/* Initialize sub-systems that use `BKE_appdir.h`. */
IMB_init();
#ifndef WITH_PYTHON_MODULE
/* First test for background-mode (#Global.background) */
BLI_argsParse(ba, 1, NULL, NULL);
main_signal_setup();
#endif
/* After parsing number of threads argument. */ /* After parsing number of threads argument. */
BLI_task_scheduler_init(); BLI_task_scheduler_init();
/* After parsing `--env-system-datafiles` which control where paths are searched
* (color-management) uses BKE_appdir to initialize. */
IMB_init();
#ifdef WITH_FFMPEG #ifdef WITH_FFMPEG
IMB_ffmpeg_init(); IMB_ffmpeg_init();
#endif #endif

View File

@@ -48,7 +48,6 @@
# include "BKE_blender_version.h" # include "BKE_blender_version.h"
# include "BKE_context.h" # include "BKE_context.h"
# include "BKE_appdir.h"
# include "BKE_global.h" # include "BKE_global.h"
# include "BKE_image.h" # include "BKE_image.h"
# include "BKE_lib_id.h" # include "BKE_lib_id.h"
@@ -57,7 +56,9 @@
# include "BKE_scene.h" # include "BKE_scene.h"
# include "BKE_sound.h" # include "BKE_sound.h"
# include "IMB_imbuf.h" # ifdef WITH_FFMPEG
# include "IMB_imbuf.h"
# endif
# ifdef WITH_PYTHON # ifdef WITH_PYTHON
# include "BPY_extern_python.h" # include "BPY_extern_python.h"
@@ -1204,8 +1205,6 @@ static int arg_handle_playback_mode(int argc, const char **argv, void *UNUSED(da
{ {
/* not if -b was given first */ /* not if -b was given first */
if (G.background == 0) { if (G.background == 0) {
BKE_appdir_init();
IMB_init();
# ifdef WITH_FFMPEG # ifdef WITH_FFMPEG
/* Setup FFmpeg with current debug flags. */ /* Setup FFmpeg with current debug flags. */
IMB_ffmpeg_init(); IMB_ffmpeg_init();
@@ -2059,7 +2058,24 @@ void main_args_setup(bContext *C, bArgs *ba)
/* end argument processing after -- */ /* end argument processing after -- */
BLI_argsAdd(ba, -1, "--", NULL, CB(arg_handle_arguments_end), NULL); BLI_argsAdd(ba, -1, "--", NULL, CB(arg_handle_arguments_end), NULL);
/* first pass: background mode, disable python and commands that exit after usage */ /* Pass 0: Environment Setup
*
* It's important these run before any initialization is done, since they set up
* the environment used to access data-files, which are be used when initializing
* sub-systems such as color management. */
BLI_argsAdd(
ba, 0, NULL, "--python-use-system-env", CB(arg_handle_python_use_system_env_set), NULL);
/* Note that we could add used environment variables too. */
BLI_argsAdd(
ba, 0, NULL, "--env-system-datafiles", CB_EX(arg_handle_env_system_set, datafiles), NULL);
BLI_argsAdd(
ba, 0, NULL, "--env-system-scripts", CB_EX(arg_handle_env_system_set, scripts), NULL);
BLI_argsAdd(ba, 0, NULL, "--env-system-python", CB_EX(arg_handle_env_system_set, python), NULL);
/* Pass 1: Background Mode & Settings
*
* Also and commands that exit after usage. */
BLI_argsAdd(ba, 1, "-h", "--help", CB(arg_handle_print_help), ba); BLI_argsAdd(ba, 1, "-h", "--help", CB(arg_handle_print_help), ba);
/* Windows only */ /* Windows only */
BLI_argsAdd(ba, 1, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba); BLI_argsAdd(ba, 1, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba);
@@ -2242,17 +2258,7 @@ void main_args_setup(bContext *C, bArgs *ba)
BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL); BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL);
BLI_argsAdd(ba, 1, NULL, "--enable-event-simulate", CB(arg_handle_enable_event_simulate), NULL); BLI_argsAdd(ba, 1, NULL, "--enable-event-simulate", CB(arg_handle_enable_event_simulate), NULL);
/* TODO, add user env vars? */ /* Pass 2: Custom Window Stuff. */
BLI_argsAdd(
ba, 1, NULL, "--env-system-datafiles", CB_EX(arg_handle_env_system_set, datafiles), NULL);
BLI_argsAdd(
ba, 1, NULL, "--env-system-scripts", CB_EX(arg_handle_env_system_set, scripts), NULL);
BLI_argsAdd(ba, 1, NULL, "--env-system-python", CB_EX(arg_handle_env_system_set, python), NULL);
BLI_argsAdd(
ba, 1, NULL, "--python-use-system-env", CB(arg_handle_python_use_system_env_set), NULL);
/* second pass: custom window stuff */
BLI_argsAdd(ba, 2, "-p", "--window-geometry", CB(arg_handle_window_geometry), NULL); BLI_argsAdd(ba, 2, "-p", "--window-geometry", CB(arg_handle_window_geometry), NULL);
BLI_argsAdd(ba, 2, "-w", "--window-border", CB(arg_handle_with_borders), NULL); BLI_argsAdd(ba, 2, "-w", "--window-border", CB(arg_handle_with_borders), NULL);
BLI_argsAdd(ba, 2, "-W", "--window-fullscreen", CB(arg_handle_without_borders), NULL); BLI_argsAdd(ba, 2, "-W", "--window-fullscreen", CB(arg_handle_without_borders), NULL);
@@ -2263,11 +2269,11 @@ void main_args_setup(bContext *C, bArgs *ba)
BLI_argsAdd(ba, 2, "-r", NULL, CB_EX(arg_handle_register_extension, silent), ba); BLI_argsAdd(ba, 2, "-r", NULL, CB_EX(arg_handle_register_extension, silent), ba);
BLI_argsAdd(ba, 2, NULL, "--no-native-pixels", CB(arg_handle_native_pixels_set), ba); BLI_argsAdd(ba, 2, NULL, "--no-native-pixels", CB(arg_handle_native_pixels_set), ba);
/* third pass: disabling things and forcing settings */ /* Pass 3: Disabling Things & Forcing Settings. */
BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, CB(arg_handle_audio_disable), NULL); BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, CB(arg_handle_audio_disable), NULL);
BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, CB(arg_handle_audio_set), NULL); BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, CB(arg_handle_audio_set), NULL);
/* fourth pass: processing arguments */ /* Pass 4: Processing Arguments. */
BLI_argsAdd(ba, 4, "-f", "--render-frame", CB(arg_handle_render_frame), C); BLI_argsAdd(ba, 4, "-f", "--render-frame", CB(arg_handle_render_frame), C);
BLI_argsAdd(ba, 4, "-a", "--render-anim", CB(arg_handle_render_animation), C); BLI_argsAdd(ba, 4, "-a", "--render-anim", CB(arg_handle_render_animation), C);
BLI_argsAdd(ba, 4, "-S", "--scene", CB(arg_handle_scene_set), C); BLI_argsAdd(ba, 4, "-S", "--scene", CB(arg_handle_scene_set), C);