Blender V4.3
wm_init_exit.cc File Reference
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include "DNA_genfile.h"
#include "DNA_scene_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_task.h"
#include "BLI_threads.h"
#include "BLI_timer.h"
#include "BLI_utildefines.h"
#include "BLO_undofile.hh"
#include "BLO_writefile.hh"
#include "BKE_blender.hh"
#include "BKE_blendfile.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_icons.h"
#include "BKE_image.hh"
#include "BKE_keyconfig.h"
#include "BKE_lib_remap.hh"
#include "BKE_main.hh"
#include "BKE_mball_tessellate.hh"
#include "BKE_preview_image.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "BKE_sound.h"
#include "BKE_vfont.hh"
#include "BKE_addon.h"
#include "BKE_appdir.hh"
#include "BKE_blender_cli_command.hh"
#include "BKE_mask.h"
#include "BKE_material.h"
#include "BKE_studiolight.h"
#include "BKE_subdiv.hh"
#include "BKE_tracking.h"
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "GHOST_C-api.h"
#include "RNA_define.hh"
#include "WM_api.hh"
#include "WM_message.hh"
#include "WM_types.hh"
#include "wm.hh"
#include "wm_cursors.hh"
#include "wm_event_system.hh"
#include "wm_files.hh"
#include "wm_platform_support.hh"
#include "wm_surface.hh"
#include "wm_window.hh"
#include "ED_anim_api.hh"
#include "ED_asset.hh"
#include "ED_gpencil_legacy.hh"
#include "ED_grease_pencil.hh"
#include "ED_keyframes_edit.hh"
#include "ED_keyframing.hh"
#include "ED_node.hh"
#include "ED_render.hh"
#include "ED_screen.hh"
#include "ED_space_api.hh"
#include "ED_undo.hh"
#include "ED_util.hh"
#include "BLF_api.hh"
#include "BLT_lang.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "UI_string_search.hh"
#include "GPU_compilation_subprocess.hh"
#include "GPU_context.hh"
#include "GPU_init_exit.hh"
#include "GPU_material.hh"
#include "COM_compositor.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "DRW_engine.hh"

Go to the source code of this file.

Functions

 CLG_LOGREF_DECLARE_GLOBAL (WM_LOG_OPERATORS, "wm.operator")
 
 CLG_LOGREF_DECLARE_GLOBAL (WM_LOG_HANDLERS, "wm.handler")
 
 CLG_LOGREF_DECLARE_GLOBAL (WM_LOG_EVENTS, "wm.event")
 
 CLG_LOGREF_DECLARE_GLOBAL (WM_LOG_KEYMAPS, "wm.keymap")
 
 CLG_LOGREF_DECLARE_GLOBAL (WM_LOG_TOOLS, "wm.tool")
 
 CLG_LOGREF_DECLARE_GLOBAL (WM_LOG_MSGBUS_PUB, "wm.msgbus.pub")
 
 CLG_LOGREF_DECLARE_GLOBAL (WM_LOG_MSGBUS_SUB, "wm.msgbus.sub")
 
static void wm_init_scripts_extensions_once (bContext *C)
 
void WM_init_state_start_with_console_set (bool value)
 
void WM_init_gpu ()
 
static void sound_jack_sync_callback (Main *bmain, int mode, double time)
 
void WM_init (bContext *C, int argc, const char **argv)
 
static bool wm_init_splash_show_on_startup_check ()
 
void WM_init_splash_on_startup (bContext *C)
 
void WM_init_splash (bContext *C)
 
static void free_openrecent ()
 
static int wm_exit_handler (bContext *C, const wmEvent *event, void *userdata)
 
void wm_exit_schedule_delayed (const bContext *C)
 
void UV_clipboard_free ()
 
void WM_exit_ex (bContext *C, const bool do_python_exit, const bool do_user_exit_actions)
 
void WM_exit (bContext *C, const int exit_code)
 
void WM_script_tag_reload ()
 

Variables

static bool wm_start_with_console = false
 
static bool gpu_is_init = false
 

Detailed Description

Manage initializing resources and correctly shutting down.

Definition in file wm_init_exit.cc.

Function Documentation

◆ CLG_LOGREF_DECLARE_GLOBAL() [1/7]

CLG_LOGREF_DECLARE_GLOBAL ( WM_LOG_EVENTS ,
"wm.event"  )

◆ CLG_LOGREF_DECLARE_GLOBAL() [2/7]

CLG_LOGREF_DECLARE_GLOBAL ( WM_LOG_HANDLERS ,
"wm.handler"  )

◆ CLG_LOGREF_DECLARE_GLOBAL() [3/7]

CLG_LOGREF_DECLARE_GLOBAL ( WM_LOG_KEYMAPS ,
"wm.keymap"  )

◆ CLG_LOGREF_DECLARE_GLOBAL() [4/7]

CLG_LOGREF_DECLARE_GLOBAL ( WM_LOG_MSGBUS_PUB ,
"wm.msgbus.pub"  )

◆ CLG_LOGREF_DECLARE_GLOBAL() [5/7]

CLG_LOGREF_DECLARE_GLOBAL ( WM_LOG_MSGBUS_SUB ,
"wm.msgbus.sub"  )

◆ CLG_LOGREF_DECLARE_GLOBAL() [6/7]

CLG_LOGREF_DECLARE_GLOBAL ( WM_LOG_OPERATORS ,
"wm.operator"  )

◆ CLG_LOGREF_DECLARE_GLOBAL() [7/7]

CLG_LOGREF_DECLARE_GLOBAL ( WM_LOG_TOOLS ,
"wm.tool"  )

◆ free_openrecent()

static void free_openrecent ( )
static

Definition at line 425 of file wm_init_exit.cc.

References BLI_freelistN(), G, LISTBASE_FOREACH, and MEM_freeN().

Referenced by WM_exit_ex().

◆ sound_jack_sync_callback()

◆ UV_clipboard_free()

void UV_clipboard_free ( )

Definition at line 398 of file uvedit_clipboard.cc.

References uv_clipboard.

Referenced by uv_copy_exec(), and WM_exit_ex().

◆ WM_exit()

void WM_exit ( bContext * C,
int exit_code )

Main exit function to close Blender ordinarily.

Note
Use wm_exit_schedule_delayed() to close Blender from an operator. Might leak memory otherwise.
Parameters
exit_codePassed to #exit, typically #EXIT_SUCCESS or #EXIT_FAILURE should be used. With failure being used for an early exit when parsing command line arguments fails. Note that any exit-code besides #EXIT_SUCCESS calls WM_exit_ex with its do_user_exit_actions argument set to false.

Definition at line 700 of file wm_init_exit.cc.

References false, G, printf, and WM_exit_ex().

Referenced by CocoaAppDelegate::application:openFile:, arg_handle_python_expr_run(), arg_handle_python_file_run(), arg_handle_python_text_run(), handle_load_file(), main(), wm_exit_handler(), and WM_init().

◆ WM_exit_ex()

void WM_exit_ex ( bContext * C,
bool do_python_exit,
bool do_user_exit_actions )

Main exit function (implementation).

Note
Unlike WM_exit this does not call exit(), the caller is responsible for this.
Parameters
CThe context or null, a null context implies do_user_exit_actions == false & prevents some editor-exit operations from running.
do_python_exitExit the Python interpreter (unless WITH_PYTHON_MODULE is enabled).
do_user_exit_actionsWhen enabled perform actions associated with a user having been using Blender then exiting. Actions such as writing the auto-save and writing any changes to preferences. Set to false in background mode or when exiting because of failed command line argument parsing. In general automated actions where the user isn't making changes should pass in false too.

Definition at line 458 of file wm_init_exit.cc.

References ANIM_driver_vars_copybuf_free(), ANIM_drivers_copybuf_free(), ANIM_fcurves_copybuf_free(), ANIM_fmodifiers_copybuf_free(), ANIM_keyingset_infos_exit(), BKE_addon_pref_type_free(), BKE_appdir_exit(), BKE_blender_atexit(), BKE_blender_cli_command_free_all(), BKE_blender_free(), BKE_blender_userdef_data_free(), BKE_blendfile_userdef_write_all(), BKE_image_free_unused_gpu_textures(), BKE_keyconfig_pref_type_free(), BKE_mask_clipboard_free(), BKE_materials_exit(), BKE_mball_cubeTable_free(), BKE_sound_exit(), BKE_tempdir_base(), BKE_tempdir_session_purge(), BKE_tracking_clipboard_free(), BKE_vfont_clipboard_free(), BLENDER_QUIT_FILE, BLF_exit(), BLI_assert, BLI_path_join, BLI_task_scheduler_exit(), BLI_threadapi_exit(), BLI_timer_free(), BLO_write_file(), BLT_lang_free(), BPY_python_end(), BPY_run_string_eval(), CLG_exit(), COM_deinitialize(), CTX_data_main(), CTX_free(), CTX_py_init_get(), CTX_wm_manager(), CTX_wm_window_set(), DNA_sdna_current_free(), DRW_gpu_context_destroy(), DRW_gpu_context_disable_ex(), DRW_gpu_context_enable_ex(), blender::draw::DRW_subdiv_free(), ED_editors_exit(), ED_editors_flush_edits(), ED_file_exit(), ED_gpencil_anim_copybuf_free(), ED_gpencil_strokes_copybuf_free(), ED_node_clipboard_free(), ED_preview_free_dbase(), ED_preview_restart_queue_free(), ED_screen_exit(), ED_undosys_type_free(), FILE_MAX, free_openrecent(), G, G_FILE_RECOVER_WRITE, G_FLAG_USERPREF_NO_SAVE_ON_EXIT, GPU_exit(), gpu_is_init, GPU_pass_cache_free(), GPU_shader_cache_dir_clear_old(), LISTBASE_FOREACH, printf, RE_engines_exit(), RE_FreeAllRender(), RNA_exit(), UI_exit(), USER_PREF_FLAG_SAVE, UV_clipboard_free(), wmWindowManager::windows, wm_autosave_delete(), wm_clipboard_free(), wm_dropbox_free(), WM_event_remove_handlers(), wm_ghost_exit(), wm_gizmogrouptype_free(), wm_gizmomaptypes_free(), wm_gizmotype_free(), WM_jobs_kill_all(), WM_menutype_free(), wm_operatortype_free(), WM_paneltype_clear(), wm_surfaces_free(), wm_test_autorun_revert_action_set(), WM_uilisttype_free(), WM_window_get_active_screen(), and blender::ui::string_search::write_recent_searches_file().

Referenced by bpy_atexit(), and WM_exit().

◆ wm_exit_handler()

static int wm_exit_handler ( bContext * C,
const wmEvent * event,
void * userdata )
static

Definition at line 434 of file wm_init_exit.cc.

References UNUSED_VARS, WM_exit(), and WM_UI_HANDLER_BREAK.

Referenced by wm_exit_schedule_delayed().

◆ wm_exit_schedule_delayed()

void wm_exit_schedule_delayed ( const bContext * C)

◆ WM_init()

void WM_init ( bContext * C,
int argc,
const char ** argv )

Initialize Blender and load the startup file & preferences (only called once).

NOTE(@ideasman42): Startup file and order of initialization.

Loading BLENDER_STARTUP_FILE, BLENDER_USERPREF_FILE, starting Python and other sub-systems, have inter-dependencies, for example.

  • Some sub-systems depend on the preferences (initializing icons depend on the theme).
  • Add-ons depends on the preferences to know what has been enabled.
  • Add-ons depends on the window-manger to register their key-maps.
  • Evaluating the startup file depends on Python for animation-drivers (see #89046).
  • Starting Python depends on the startup file so key-maps can be added in the window-manger.

Loading preferences early, then application subsystems and finally the startup data would simplify things if it weren't for key-maps being part of the window-manager which is blend file data. Creating a dummy window-manager early, or moving the key-maps into the preferences would resolve this and may be worth looking into long-term, see: D12184 for details.

Definition at line 197 of file wm_init_exit.cc.

References BIFICONID_LAST_STATIC, BKE_addon_pref_type_init(), BKE_icons_init(), BKE_keyconfig_pref_type_init(), BKE_library_callback_free_notifier_reference_set(), BKE_library_callback_remap_editor_id_reference_set(), BKE_main_blendfile_path_from_global(), BKE_preview_images_init(), BKE_region_callback_free_gizmomap_set(), BKE_region_callback_refresh_tag_gizmomap_set(), BKE_sound_jack_sync_callback_set(), BKE_spacedata_callback_id_remap_set(), BKE_studiolight_init(), BLF_init(), BLI_assert, BLT_lang_init(), BLT_lang_set(), BPY_python_reset(), BPY_python_start(), CTX_py_init_set(), DEG_editors_set_update_cb(), ED_file_init(), ED_node_init_butfuncs(), ED_render_clear_mtex_copybuf(), ED_render_id_flush_update(), ED_render_scene_update(), ED_spacedata_id_remap_single(), ED_spacemacros_init(), ED_spacetypes_init(), ED_undosys_type_init(), G, G_FILE_NO_UI, G_MAIN, GHOST_kConsoleWindowStateHideForNonConsoleLaunch, GHOST_kConsoleWindowStateShow, GHOST_setConsoleWindowState(), GPU_context_active_get(), GPU_context_begin_frame(), GPU_context_end_frame(), GPU_render_begin(), GPU_render_end(), blender::bke::subdiv::init(), blender::ui::string_search::read_recent_searches_file(), sound_jack_sync_callback(), STRNCPY, UI_init(), UNUSED_VARS, wmHomeFileRead_Params::use_data, WM_exit(), wm_ghost_init(), wm_gizmogrouptype_init(), wm_gizmomap_remove(), WM_gizmomap_tag_refresh(), wm_gizmotype_init(), wm_history_file_read(), wm_homefile_read_ex(), wm_homefile_read_post(), wm_init_cursor_data(), WM_init_gpu(), wm_init_scripts_extensions_once(), WM_init_state_app_template_get(), WM_keyconfig_init(), WM_keyconfig_update(), WM_keyconfig_update_postpone_begin(), WM_keyconfig_update_postpone_end(), WM_main_remap_editor_id_reference(), WM_main_remove_notifier_reference(), WM_menutype_init(), WM_msgbus_types_init(), wm_operatortypes_register(), WM_paneltype_init(), WM_platform_support_perform_checks(), wm_start_with_console, and WM_uilisttype_init().

Referenced by main().

◆ WM_init_gpu()

◆ wm_init_scripts_extensions_once()

static void wm_init_scripts_extensions_once ( bContext * C)
static

Load add-ons & app-templates once on startup.

Definition at line 414 of file wm_init_exit.cc.

References BPY_run_string_eval(), and UNUSED_VARS.

Referenced by WM_init().

◆ WM_init_splash()

◆ WM_init_splash_on_startup()

void WM_init_splash_on_startup ( bContext * C)

Show the splash screen as needed on startup.

The splash may not show depending on a file being loaded and user preferences.

Definition at line 390 of file wm_init_exit.cc.

References WM_init_splash(), and wm_init_splash_show_on_startup_check().

Referenced by main().

◆ wm_init_splash_show_on_startup_check()

static bool wm_init_splash_show_on_startup_check ( )
static

◆ WM_init_state_start_with_console_set()

void WM_init_state_start_with_console_set ( bool value)

Definition at line 129 of file wm_init_exit.cc.

References wm_start_with_console.

Referenced by arg_handle_start_with_console().

◆ WM_script_tag_reload()

void WM_script_tag_reload ( )

Needed for cases when operators are re-registered (when operator type pointers are stored).

Definition at line 712 of file wm_init_exit.cc.

References UI_interface_tag_script_reload(), and WM_gizmoconfig_update_tag_reinit_all().

Variable Documentation

◆ gpu_is_init

bool gpu_is_init = false
static

Since we cannot know in advance if we will require the draw manager context when starting blender in background mode (specially true with scripts) we defer the ghost initialization the most as possible so that it does not break anything that can run in headless mode (as in without display server attached).

Definition at line 141 of file wm_init_exit.cc.

Referenced by WM_exit_ex(), and WM_init_gpu().

◆ wm_start_with_console

bool wm_start_with_console = false
static

Definition at line 127 of file wm_init_exit.cc.

Referenced by WM_init(), and WM_init_state_start_with_console_set().