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.
This commit is contained in:
Campbell Barton 2020-10-04 21:48:48 +11:00
parent 7456ac6e4b
commit 9d30fade3e
Notes: blender-bot 2023-02-14 00:44:02 +01:00
Referenced by commit 9ea345d1cf, Fix animation player initialization
3 changed files with 46 additions and 1 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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