Example #1
0
/* note, doesnt run exit() call WM_exit() for that */
void WM_exit_ext(bContext *C, const short do_python)
{
	wmWindow *win;

	sound_exit();


	/* first wrap up running stuff, we assume only the active WM is running */
	/* modal handlers are on window level freed, others too? */
	/* note; same code copied in wm_files.c */
	if (C && CTX_wm_manager(C)) {
		
		WM_jobs_stop_all(CTX_wm_manager(C));
		
		for (win = CTX_wm_manager(C)->windows.first; win; win = win->next) {
			
			CTX_wm_window_set(C, win);  /* needed by operator close callbacks */
			WM_event_remove_handlers(C, &win->handlers);
			WM_event_remove_handlers(C, &win->modalhandlers);
			ED_screen_exit(C, win, win->screen);
		}
	}
	wm_operatortype_free();
	wm_dropbox_free();
	WM_menutype_free();
	
	/* all non-screen and non-space stuff editors did, like editmode */
	if (C)
		ED_editors_exit(C);

//	XXX	
//	BIF_GlobalReebFree();
//	BIF_freeRetarget();
	BIF_freeTemplates(C);
	
	BKE_vfont_free_global_ttf(); /* bke_font.h */

	free_openrecent();
	
	BKE_mball_cubeTable_free();
	
	ED_preview_free_dbase();  /* frees a Main dbase, before free_blender! */

	if (C && CTX_wm_manager(C))
		wm_free_reports(C);  /* before free_blender! - since the ListBases get freed there */

	seq_free_clipboard(); /* sequencer.c */
	BKE_tracking_clipboard_free();
		
	free_blender();  /* blender.c, does entire library and spacetypes */
//	free_matcopybuf();
	free_anim_copybuf();
	free_anim_drivers_copybuf();
	free_fmodifiers_copybuf();
	free_posebuf();

	BLF_exit();

#ifdef WITH_INTERNATIONAL
	BLF_free_unifont();
#endif
	
	ANIM_keyingset_infos_exit();
	
	RE_FreeAllRender();
	RE_engines_exit();
	
//	free_txt_data();
	

#ifdef WITH_PYTHON
	/* option not to close python so we can use 'atexit' */
	if (do_python) {
		/* XXX - old note */
		/* before free_blender so py's gc happens while library still exists */
		/* needed at least for a rare sigsegv that can happen in pydrivers */

		/* Update for blender 2.5, move after free_blender because blender now holds references to PyObject's
		 * so decref'ing them after python ends causes bad problems every time
		 * the pyDriver bug can be fixed if it happens again we can deal with it then */
		BPY_python_end();
	}
#else
	(void)do_python;
#endif

	GPU_global_buffer_pool_free();
	GPU_free_unused_buffers();
	GPU_extensions_exit();

	if (!G.background) {
		BKE_undo_save_quit();  /* saves quit.blend if global undo is on */
	}
	BKE_reset_undo(); 
	
	ED_file_exit(); /* for fsmenu */

	UI_exit();
	BKE_userdef_free();

	RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */
	
	wm_ghost_exit();

	CTX_free(C);
#ifdef WITH_GAMEENGINE
	SYS_DeleteSystem(SYS_GetSystem());
#endif
	
	GHOST_DisposeSystemPaths();

	if (MEM_get_memory_blocks_in_use() != 0) {
		printf("Error: Not freed memory blocks: %d\n", MEM_get_memory_blocks_in_use());
		MEM_printmemlist();
	}
	wm_autosave_delete();
	
	printf("\nBlender quit\n");
	
#ifdef WIN32   
	/* ask user to press a key when in debug mode */
	if (G.debug & G_DEBUG) {
		printf("Press any key to exit . . .\n\n");
		wait_for_console_key();
	}
#endif 
}
Example #2
0
/* op can be NULL */
int WM_read_homefile(bContext *C, ReportList *UNUSED(reports), short from_memory)
{
	ListBase wmbase;
	char tstr[FILE_MAX];
	int success = 0;
	
	BKE_vfont_free_global_ttf(); /* still weird... what does it here? */
		
	G.relbase_valid = 0;
	if (!from_memory) {
		char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
		if (cfgdir) {
			BLI_make_file_string(G.main->name, tstr, cfgdir, BLENDER_STARTUP_FILE);
		}
		else {
			tstr[0] = '\0';
			from_memory = 1;
		}
	}
	
	/* prevent loading no UI */
	G.fileflags &= ~G_FILE_NO_UI;
	
	/* put aside screens to match with persistent windows later */
	wm_window_match_init(C, &wmbase); 
	
	if (!from_memory && BLI_exists(tstr)) {
		success = (BKE_read_file(C, tstr, NULL) != BKE_READ_FILE_FAIL);
		
		if (U.themes.first == NULL) {
			printf("\nError: No valid "STRINGIFY (BLENDER_STARTUP_FILE)", fall back to built-in default.\n\n");
			success = 0;
		}
	}
	if (success == 0) {
		success = BKE_read_file_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL);
		if (wmbase.first == NULL) wm_clear_default_size(C);

#ifdef WITH_PYTHON_SECURITY /* not default */
		/* use alternative setting for security nuts
		 * otherwise we'd need to patch the binary blob - startup.blend.c */
		U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
#endif
	}
	
	/* prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake. Screws up autosaves otherwise
	 * can remove this eventually, only in a 2.53 and older, now its not written */
	G.fileflags &= ~G_FILE_RELATIVE_REMAP;
	
	/* check userdef before open window, keymaps etc */
	wm_init_userdef(C);
	
	/* match the read WM with current WM */
	wm_window_match_do(C, &wmbase); 
	WM_check(C); /* opens window(s), checks keymaps */

	G.main->name[0] = '\0';

	/* When loading factory settings, the reset solid OpenGL lights need to be applied. */
	if (!G.background) GPU_default_lights();
	
	/* XXX */
	G.save_over = 0;    // start with save preference untitled.blend
	G.fileflags &= ~G_FILE_AUTOPLAY;    /*  disable autoplay in startup.blend... */
//	mainwindow_set_filename_to_title("");	// empty string re-initializes title to "Blender"
	
//	refresh_interface_font();
	
//	undo_editmode_clear();
	BKE_reset_undo();
	BKE_write_undo(C, "original");  /* save current state */

	ED_editors_init(C);
	DAG_on_visible_update(CTX_data_main(C), TRUE);

#ifdef WITH_PYTHON
	if (CTX_py_init_get(C)) {
		/* sync addons, these may have changed from the defaults */
		BPY_string_exec(C, "__import__('addon_utils').reset_all()");

		BPY_driver_reset();
		BPY_app_handlers_reset(FALSE);
		BPY_modules_load_user(C);
	}
#endif

	WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL);

	/* in background mode the scene will stay NULL */
	if (!G.background) {
		CTX_wm_window_set(C, NULL); /* exits queues */
	}

	return TRUE;
}