Refactor: initialize IMB after parsing settings

Avoid awkward kludges with IMB_init/exit & IMB_ffmpeg_init calls.

The animation player was responsible for calling IMB_exit, not IMB_init,
this complicated drag & drop which needed to re-internalize IMB before
returning.

Delay initializing IMB since none of the other argument handlers
depend on it, make wm_main_playanim_intern responsible for calling
both initialization & exit calls for IMB.

Also expand code comments for ARG_PASS_SETTINGS.
This commit is contained in:
Campbell Barton
2023-11-09 13:46:04 +11:00
parent 368b38be37
commit 704985152e
3 changed files with 18 additions and 13 deletions

View File

@@ -1712,6 +1712,11 @@ static bool wm_main_playanim_intern(int argc, const char **argv, PlayArgs *args_
ps.font_id = -1;
IMB_init();
#ifdef WITH_FFMPEG
IMB_ffmpeg_init();
#endif
STRNCPY(ps.display_ctx.display_settings.display_device,
IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE));
IMB_colormanagement_init_default_view_settings(&ps.display_ctx.view_settings,
@@ -2145,7 +2150,8 @@ static bool wm_main_playanim_intern(int argc, const char **argv, PlayArgs *args_
BLF_exit();
/* NOTE: Must happen before GPU Context destruction as GPU resources are released via
* Color Management module. Must be re-initialized in the case of drag & drop. */
* Color Management module.
* NOTE: there is no #IMB_ffmpeg_exit. */
IMB_exit();
if (ps.ghost_data.gpu_context) {
@@ -2161,9 +2167,6 @@ static bool wm_main_playanim_intern(int argc, const char **argv, PlayArgs *args_
/* Early exit, IMB and BKE should be exited only in end. */
if (ps.argv_next) {
/* Ensure drag & drop runs with a valid IMB state. */
IMB_init();
args_next->argc = ps.argc_next;
args_next->argv = ps.argv_next;
return true;

View File

@@ -486,16 +486,23 @@ int main(int argc,
/* 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) */
/* The settings pass includes:
* - Background-mode assignment (#Global.background), checked by other subsystems
* which may be skipped in background mode.
* - The animation player may be launched which takes over argument passing,
* initializes the sub-systems it needs which have not yet been started.
* The animation player will call `exit(..)` too, so code after this call
* never runs when it's invoked.
* - All the `--debug-*` flags.
*/
BLI_args_parse(ba, ARG_PASS_SETTINGS, nullptr, nullptr);
main_signal_setup();
#endif
/* Must be initialized after #BKE_appdir_init to account for color-management paths. */
IMB_init();
#ifdef WITH_FFMPEG
/* Keep after #ARG_PASS_SETTINGS since debug flags are checked. */
IMB_ffmpeg_init();

View File

@@ -1389,11 +1389,6 @@ static int arg_handle_playback_mode(int argc, const char **argv, void * /*data*/
{
/* Ignore the animation player if `-b` was given first. */
if (G.background == 0) {
# ifdef WITH_FFMPEG
/* Setup FFmpeg with current debug flags. */
IMB_ffmpeg_init();
# endif
/* Skip this argument (`-a`). */
WM_main_playanim(argc - 1, argv + 1);