Blender  V3.3
Functions | Variables
wm_init_exit.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_task.h"
#include "BLI_threads.h"
#include "BLI_timer.h"
#include "BLI_utildefines.h"
#include "BLO_undofile.h"
#include "BLO_writefile.h"
#include "BKE_blender.h"
#include "BKE_blendfile.h"
#include "BKE_callbacks.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_icons.h"
#include "BKE_image.h"
#include "BKE_keyconfig.h"
#include "BKE_lib_remap.h"
#include "BKE_main.h"
#include "BKE_mball_tessellate.h"
#include "BKE_node.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sound.h"
#include "BKE_vfont.h"
#include "BKE_addon.h"
#include "BKE_appdir.h"
#include "BKE_mask.h"
#include "BKE_material.h"
#include "BKE_studiolight.h"
#include "BKE_subdiv.h"
#include "BKE_tracking.h"
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "SEQ_clipboard.h"
#include "IMB_thumbs.h"
#include "GHOST_C-api.h"
#include "GHOST_Path-api.h"
#include "RNA_define.h"
#include "WM_api.h"
#include "WM_message.h"
#include "WM_types.h"
#include "wm.h"
#include "wm_cursors.h"
#include "wm_event_system.h"
#include "wm_files.h"
#include "wm_platform_support.h"
#include "wm_surface.h"
#include "wm_window.h"
#include "ED_anim_api.h"
#include "ED_armature.h"
#include "ED_asset.h"
#include "ED_gpencil.h"
#include "ED_keyframes_edit.h"
#include "ED_keyframing.h"
#include "ED_node.h"
#include "ED_render.h"
#include "ED_screen.h"
#include "ED_space_api.h"
#include "ED_undo.h"
#include "ED_util.h"
#include "ED_view3d.h"
#include "BLF_api.h"
#include "BLT_lang.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "GPU_context.h"
#include "GPU_init_exit.h"
#include "GPU_material.h"
#include "COM_compositor.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "DRW_engine.h"

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_reports (bContext *C)
 
static void wm_free_reports (wmWindowManager *wm)
 
void WM_init_state_start_with_console_set (bool value)
 
void WM_init_opengl (void)
 
static void sound_jack_sync_callback (Main *bmain, int mode, double time)
 
void WM_init (bContext *C, int argc, const char **argv)
 
void WM_init_splash (bContext *C)
 
static void free_openrecent (void)
 
static int wm_exit_handler (bContext *C, const wmEvent *event, void *userdata)
 
void wm_exit_schedule_delayed (const bContext *C)
 
void WM_exit_ex (bContext *C, const bool do_python)
 
void WM_exit (bContext *C)
 Main exit function to close Blender ordinarily. More...
 
void WM_script_tag_reload (void)
 

Variables

static bool wm_start_with_console = false
 
static bool opengl_is_init = false
 

Detailed Description

Manage initializing resources and correctly shutting down.

Definition in file wm_init_exit.c.

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 ( void  )
static

Definition at line 381 of file wm_init_exit.c.

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

Referenced by WM_exit_ex().

◆ sound_jack_sync_callback()

static void sound_jack_sync_callback ( Main bmain,
int  mode,
double  time 
)
static

◆ WM_exit()

void WM_exit ( struct bContext C)

Main exit function to close Blender ordinarily.

Note
Use wm_exit_schedule_delayed() to close Blender from an operator. Might leak memory otherwise.

Definition at line 646 of file wm_init_exit.c.

References C, G, G_DEBUG, and WM_exit_ex().

Referenced by arg_handle_load_file(), main(), and wm_exit_handler().

◆ WM_exit_ex()

void WM_exit_ex ( struct bContext C,
bool  do_python 
)
Note
doesn't run exit() call WM_exit() for that.

Definition at line 434 of file wm_init_exit.c.

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_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_node_clipboard_free(), BKE_sound_exit(), BKE_subdiv_exit(), BKE_tempdir_base(), BKE_tempdir_session_purge(), BKE_tracking_clipboard_free(), BKE_vfont_clipboard_free(), BLENDER_QUIT_FILE, BLF_exit(), BLI_join_dirfile(), BLI_task_scheduler_exit(), BLI_threadapi_exit(), BLI_timer_free(), BLO_memfile_write_file(), BLO_write_file(), BLT_lang_free(), BPY_python_end(), BPY_run_string_eval(), C, 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_opengl_context_destroy(), DRW_opengl_context_disable_ex(), DRW_opengl_context_enable_ex(), DRW_subdiv_free(), ED_assetlist_storage_exit(), ED_editors_exit(), ED_editors_flush_edits(), ED_file_exit(), ED_gpencil_anim_copybuf_free(), ED_gpencil_strokes_copybuf_free(), ED_preview_free_dbase(), ED_preview_restart_queue_free(), ED_screen_exit(), ED_undosys_stack_memfile_get_active(), ED_undosys_type_free(), FILE_MAX, free_openrecent(), G, G_FILE_COMPRESS, G_FLAG_USERPREF_NO_SAVE_ON_EXIT, GHOST_DisposeSystemPaths(), GPU_exit(), GPU_pass_cache_free(), LISTBASE_FOREACH, NULL, opengl_is_init, RE_engines_exit(), RE_FreeAllRender(), RNA_exit(), SEQ_clipboard_free(), UI_exit(), wmWindowManager::undo_stack, USER_PREF_FLAG_SAVE, void, wmWindowManager::windows, wm_autosave_delete(), wm_dropbox_free(), WM_event_remove_handlers(), wm_free_reports(), 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(), and WM_window_get_active_screen().

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 413 of file wm_init_exit.c.

References C, 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_free_reports()

static void wm_free_reports ( wmWindowManager wm)
static

Definition at line 141 of file wm_init_exit.c.

References BKE_reports_clear(), and wmWindowManager::reports.

Referenced by WM_exit_ex().

◆ WM_init()

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

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

NOTE(@campbellbarton): 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 T89046).
  • 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 212 of file wm_init_exit.c.

References BIFICONID_LAST, 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_material_copybuf_clear(), 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(), BKE_subdiv_init(), BLF_init(), BLI_assert, BLI_strncpy(), BLT_lang_init(), BLT_lang_set(), BPY_python_reset(), BPY_python_start(), C, 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_CreateSystemPaths(), GHOST_kConsoleWindowStateHideForNonConsoleLaunch, GHOST_kConsoleWindowStateShow, GHOST_setConsoleWindowState(), GPU_context_active_get(), GPU_context_begin_frame(), GPU_context_end_frame(), GPU_render_begin(), GPU_render_end(), IMB_thumb_clear_translations(), NULL, sound_jack_sync_callback(), UI_init(), UNUSED_VARS, 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_opengl(), wm_init_reports(), WM_init_state_app_template_get(), WM_main_remap_editor_id_reference(), WM_main_remove_notifier_reference(), WM_menutype_init(), WM_msgbus_types_init(), wm_operatortype_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_opengl()

void WM_init_opengl ( void  )

◆ wm_init_reports()

static void wm_init_reports ( bContext C)
static

◆ WM_init_splash()

void WM_init_splash ( bContext C)

◆ WM_init_state_start_with_console_set()

void WM_init_state_start_with_console_set ( bool  value)

Definition at line 148 of file wm_init_exit.c.

References wm_start_with_console.

Referenced by arg_handle_start_with_console().

◆ WM_script_tag_reload()

void WM_script_tag_reload ( void  )

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

Definition at line 663 of file wm_init_exit.c.

References UI_interface_tag_script_reload().

Variable Documentation

◆ opengl_is_init

bool opengl_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 160 of file wm_init_exit.c.

Referenced by WM_exit_ex(), and WM_init_opengl().

◆ wm_start_with_console

bool wm_start_with_console = false
static

Definition at line 146 of file wm_init_exit.c.

Referenced by WM_init(), and WM_init_state_start_with_console_set().