[Bf-blender-cvs] [09139e41ed4] master: Cleanup: simplify order of initialization with argument parsing

Campbell Barton noreply at git.blender.org
Tue Oct 27 08:45:57 CET 2020


Commit: 09139e41ed4eaf4d9b8943e92b8604d979dbbc92
Author: Campbell Barton
Date:   Tue Oct 27 18:21:16 2020 +1100
Branches: master
https://developer.blender.org/rB09139e41ed4eaf4d9b8943e92b8604d979dbbc92

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 9ea345d1cf82f

===================================================================

M	source/creator/creator.c
M	source/creator/creator_args.c

===================================================================

diff --git a/source/creator/creator.c b/source/creator/creator.c
index 65610ea9b70..f9aea0af301 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -403,25 +403,30 @@ int main(int argc,
    * (such as '--version' & '--help') don't report leaks. */
   MEM_use_memleak_detection(false);
 
-  BLI_argsParse(ba, 1, NULL, NULL);
-
-  main_signal_setup();
+  /* Parse environment handling arguments. */
+  BLI_argsParse(ba, 0, NULL, NULL);
 
 #else
   /* Using preferences or user startup makes no sense for #WITH_PYTHON_MODULE. */
   G.factory_startup = true;
 #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();
 
+  /* 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. */
   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
   IMB_ffmpeg_init();
 #endif
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 3b54811657d..13e8885ae5d 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -48,7 +48,6 @@
 #  include "BKE_blender_version.h"
 #  include "BKE_context.h"
 
-#  include "BKE_appdir.h"
 #  include "BKE_global.h"
 #  include "BKE_image.h"
 #  include "BKE_lib_id.h"
@@ -57,7 +56,9 @@
 #  include "BKE_scene.h"
 #  include "BKE_sound.h"
 
-#  include "IMB_imbuf.h"
+#  ifdef WITH_FFMPEG
+#    include "IMB_imbuf.h"
+#  endif
 
 #  ifdef WITH_PYTHON
 #    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 */
   if (G.background == 0) {
-    BKE_appdir_init();
-    IMB_init();
 #  ifdef WITH_FFMPEG
     /* Setup FFmpeg with current debug flags. */
     IMB_ffmpeg_init();
@@ -2059,7 +2058,24 @@ void main_args_setup(bContext *C, bArgs *ba)
   /* end argument processing after -- */
   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);
   /* Windows only */
   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, "--enable-event-simulate", CB(arg_handle_enable_event_simulate), NULL);
 
-  /* TODO, add user env vars? */
-  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 */
+  /* Pass 2: Custom Window Stuff. */
   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-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, 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, "-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, "-a", "--render-anim", CB(arg_handle_render_animation), C);
   BLI_argsAdd(ba, 4, "-S", "--scene", CB(arg_handle_scene_set), C);



More information about the Bf-blender-cvs mailing list