[Bf-blender-cvs] [9d30fade3ea] master: Fix color-management ignoring the data-path command line value

Campbell Barton noreply at git.blender.org
Sun Oct 4 13:15:43 CEST 2020


Commit: 9d30fade3ea9b03e0764ab5dc9a9263543a79a83
Author: Campbell Barton
Date:   Sun Oct 4 21:48:48 2020 +1100
Branches: master
https://developer.blender.org/rB9d30fade3ea9b03e0764ab5dc9a9263543a79a83

Fix color-management ignoring the data-path command line value

Initialize ImBuf (and color-management) after passing arguments
that set environment variables such as `--env-system-datapath`

This also fixes a bug where BKE_appdir logging failed since it was
called before the `--log` argument was passed.

Add asserts so this doesn't happen again.

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

M	source/blender/blenkernel/BKE_appdir.h
M	source/blender/blenkernel/intern/appdir.c
M	source/creator/creator.c

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

diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h
index 4488e23f791..3e52d7f3301 100644
--- a/source/blender/blenkernel/BKE_appdir.h
+++ b/source/blender/blenkernel/BKE_appdir.h
@@ -25,6 +25,8 @@ extern "C" {
 
 struct ListBase;
 
+void BKE_appdir_init(void);
+
 /* note on naming: typical _get() suffix is omitted here,
  * since its the main purpose of the API. */
 const char *BKE_appdir_folder_default(void);
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index 97ebca7692e..dbf8a312181 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -83,6 +83,35 @@ static char btempdir_session[FILE_MAX] = "";
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Initialization
+ * \{ */
+
+#ifndef NDEBUG
+static bool is_appdir_init = false;
+#  define ASSERT_IS_INIT() BLI_assert(is_appdir_init)
+#else
+#  define ASSERT_IS_INIT() ((void)0)
+#endif
+
+/**
+ * Sanity check to ensure correct API use in debug mode.
+ *
+ * Run this once the first level of arguments has been passed so we can be sure
+ * `--env-system-datafiles`, and other `--env-*` arguments has been passed.
+ *
+ * Without this any callers to this module that run early on,
+ * will miss out on changes from parsing arguments.
+ */
+void BKE_appdir_init(void)
+{
+#ifndef NDEBUG
+  is_appdir_init = true;
+#endif
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Internal Utilities
  * \{ */
@@ -198,6 +227,8 @@ static bool test_path(char *targetpath,
                       const char *folder_name,
                       const char *subfolder_name)
 {
+  ASSERT_IS_INIT();
+
   /* Only the last argument should be NULL. */
   BLI_assert(!(folder_name == NULL && (subfolder_name != NULL)));
   BLI_path_join(targetpath, targetpath_len, path_base, folder_name, subfolder_name, NULL);
@@ -231,6 +262,8 @@ static bool test_path(char *targetpath,
  */
 static bool test_env_path(char *path, const char *envvar, const bool check_is_dir)
 {
+  ASSERT_IS_INIT();
+
   const char *env_path = envvar ? BLI_getenv(envvar) : NULL;
   if (!env_path) {
     return false;
@@ -810,6 +843,7 @@ void BKE_appdir_program_path_init(const char *argv0)
  */
 const char *BKE_appdir_program_path(void)
 {
+  BLI_assert(bprogname[0]);
   return bprogname;
 }
 
@@ -818,6 +852,7 @@ const char *BKE_appdir_program_path(void)
  */
 const char *BKE_appdir_program_dir(void)
 {
+  BLI_assert(bprogdir[0]);
   return bprogdir;
 }
 
@@ -826,6 +861,8 @@ bool BKE_appdir_program_python_search(char *fullpath,
                                       const int version_major,
                                       const int version_minor)
 {
+  ASSERT_IS_INIT();
+
 #ifdef PYTHON_EXECUTABLE_NAME
   /* Passed in from the build-systems 'PYTHON_EXECUTABLE'. */
   const char *python_build_def = STRINGIFY(PYTHON_EXECUTABLE_NAME);
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 9df0ece26b5..f7b0fa3a31f 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -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();
@@ -413,9 +412,16 @@ int main(int argc,
   G.factory_startup = true;
 #endif
 
+  /* After parsing the first level of arguments as `--env-*` impact BKE_appdir behavior. */
+  BKE_appdir_init();
+
   /* 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



More information about the Bf-blender-cvs mailing list