4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2007 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
33 #include "MEM_guardedalloc.h"
34 #include "MEM_CacheLimiterC-Api.h"
36 #include "IMB_imbuf_types.h"
37 #include "IMB_imbuf.h"
39 #include "DNA_object_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_userdef_types.h"
42 #include "DNA_windowmanager_types.h"
44 #include "BKE_blender.h"
45 #include "BKE_context.h"
46 #include "BKE_curve.h"
47 #include "BKE_displist.h"
48 #include "BKE_DerivedMesh.h"
50 #include "BKE_global.h"
51 #include "BKE_library.h"
52 #include "BKE_mball.h"
53 #include "BKE_report.h"
54 #include "BKE_utildefines.h"
55 #include "BKE_packedFile.h"
57 #include "BLI_blenlib.h"
59 #include "RE_pipeline.h" /* RE_ free stuff */
61 #ifndef DISABLE_PYTHON
62 #include "BPY_extern.h"
65 #include "SYS_System.h"
67 #include "RNA_define.h"
72 #include "wm_cursors.h"
73 #include "wm_event_system.h"
76 #include "wm_window.h"
78 #include "ED_armature.h"
79 #include "ED_keyframing.h"
81 #include "ED_previewrender.h"
82 #include "ED_space_api.h"
83 #include "ED_screen.h"
86 #include "UI_interface.h"
89 #include "GPU_extensions.h"
92 #include "BKE_sound.h"
94 static void wm_init_reports(bContext *C)
96 BKE_reports_init(CTX_wm_reports(C), RPT_STORE);
98 static void wm_free_reports(bContext *C)
100 BKE_reports_clear(CTX_wm_reports(C));
105 /* only called once, for startup */
106 void WM_init(bContext *C)
109 wm_ghost_init(C); /* note: it assigns C to ghost! */
110 wm_init_cursor_data();
111 wm_operatortype_init();
113 set_free_windowmanager_cb(wm_close_and_free); /* library.c */
114 set_blender_test_break_cb(wm_window_testbreak); /* blender.c */
116 ED_spacetypes_init(); /* editors/space_api/spacetype.c */
118 ED_file_init(); /* for fsmenu */
119 ED_init_node_butfuncs();
124 init_builtin_keyingsets(); /* editors/animation/keyframing.c */
126 /* get the default database, plus a wm */
127 WM_read_homefile(C, NULL);
129 wm_init_reports(C); /* reports cant be initialized before the wm */
133 // clear_matcopybuf(); /* XXX */
135 // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
137 // init_node_butfuncs();
139 ED_preview_init_dbase();
141 GPU_extensions_init();
143 G.ndofdevice = -1; /* XXX bad initializer, needs set otherwise buttons show! */
146 BLI_strncpy(G.lib, G.sce, FILE_MAX);
149 /* free strings of open recent files */
150 static void free_openrecent(void)
152 struct RecentFile *recent;
154 for(recent = G.recent_files.first; recent; recent=recent->next)
155 MEM_freeN(recent->filename);
157 BLI_freelistN(&(G.recent_files));
163 extern ListBase editelems;
164 extern wchar_t *copybuf;
165 extern wchar_t *copybufinfo;
167 // XXX copy/paste buffer stuff...
168 extern void free_anim_copybuf();
169 extern void free_posebuf();
171 /* called in creator.c even... tsk, split this! */
172 void WM_exit(bContext *C)
178 /* first wrap up running stuff, we assume only the active WM is running */
179 /* modal handlers are on window level freed, others too? */
180 /* note; same code copied in wm_files.c */
181 if(C && CTX_wm_manager(C)) {
183 WM_jobs_stop_all(CTX_wm_manager(C));
185 for(win= CTX_wm_manager(C)->windows.first; win; win= win->next) {
187 CTX_wm_window_set(C, win); /* needed by operator close callbacks */
188 WM_event_remove_handlers(C, &win->handlers);
189 ED_screen_exit(C, win, win->screen);
192 wm_operatortype_free();
194 /* all non-screen and non-space stuff editors did, like editmode */
199 // BIF_GlobalReebFree();
200 // BIF_freeRetarget();
201 BIF_freeTemplates(C);
203 free_ttfont(); /* bke_font.h */
209 fastshade_free_render(); /* shaded view */
210 ED_preview_free_dbase(); /* frees a Main dbase, before free_blender! */
211 wm_free_reports(C); /* before free_blender! - since the ListBases get freed there */
212 free_blender(); /* blender.c, does entire library and spacetypes */
213 // free_matcopybuf();
216 // free_vertexpaint();
217 // free_imagepaint();
229 #ifndef DISABLE_PYTHON
231 /* before free_blender so py's gc happens while library still exists */
232 /* needed at least for a rare sigsegv that can happen in pydrivers */
234 /* Update for blender 2.5, move after free_blender because blender now holds references to PyObject's
235 * so decref'ing them after python ends causes bad problems every time
236 * the pyDriver bug can be fixed if it happens again we can deal with it then */
242 #ifdef WITH_QUICKTIME
247 // XXX UI_filelist_free_icons();
250 GPU_extensions_exit();
252 // if (copybuf) MEM_freeN(copybuf);
253 // if (copybufinfo) MEM_freeN(copybufinfo);
255 BKE_undo_save_quit(); // saves quit.blend if global undo is on
258 ED_file_exit(); /* for fsmenu */
263 RNA_exit(); /* should be after BPY_end_python so struct python slots are cleared */
269 SYS_DeleteSystem(SYS_GetSystem());
271 if(MEM_get_memory_blocks_in_use()!=0) {
272 printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use());
275 // delete_autosave();
277 printf("\nBlender quit\n");
280 /* ask user to press enter when in debug mode */
282 printf("press enter key to exit...\n\n");