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_sound_types.h"
42 #include "DNA_userdef_types.h"
43 #include "DNA_windowmanager_types.h"
45 #include "BKE_blender.h"
46 #include "BKE_context.h"
47 #include "BKE_curve.h"
48 #include "BKE_displist.h"
49 #include "BKE_DerivedMesh.h"
51 #include "BKE_global.h"
52 #include "BKE_library.h"
53 #include "BKE_mball.h"
54 #include "BKE_utildefines.h"
55 #include "BKE_packedFile.h"
62 #include "BLI_blenlib.h"
64 #include "RE_pipeline.h" /* RE_ free stuff */
68 #ifndef DISABLE_PYTHON
69 #include "BPY_extern.h"
72 #include "SYS_System.h"
74 #include "RNA_define.h"
79 #include "wm_cursors.h"
80 #include "wm_event_system.h"
83 #include "wm_window.h"
85 #include "ED_armature.h"
87 #include "ED_previewrender.h"
88 #include "ED_space_api.h"
89 #include "ED_screen.h"
92 #include "UI_interface.h"
95 #include "GPU_extensions.h"
101 static void sound_init_listener(void)
103 G.listener = MEM_callocN(sizeof(bSoundListener), "soundlistener");
104 G.listener->gain = 1.0;
105 G.listener->dopplerfactor = 1.0;
106 G.listener->dopplervelocity = 340.29f;
109 /* only called once, for startup */
110 void WM_init(bContext *C)
113 wm_ghost_init(C); /* note: it assigns C to ghost! */
114 wm_init_cursor_data();
115 wm_operatortype_init();
117 set_free_windowmanager_cb(wm_close_and_free); /* library.c */
118 set_blender_test_break_cb(wm_window_testbreak); /* blender.c */
120 ED_spacetypes_init(); /* editors/space_api/spacetype.c */
122 ED_file_init(); /* for fsmenu */
123 ED_init_node_butfuncs();
128 /* get the default database, plus a wm */
129 WM_read_homefile(C, NULL);
134 G.font= BMF_GetFont(BMF_kHelvetica12);
135 G.fonts= BMF_GetFont(BMF_kHelvetica10);
136 G.fontss= BMF_GetFont(BMF_kHelveticaBold8);
138 // clear_matcopybuf(); /* XXX */
140 // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
142 sound_init_listener();
143 // init_node_butfuncs();
145 ED_preview_init_dbase();
147 GPU_extensions_init();
149 G.ndofdevice = -1; /* XXX bad initializer, needs set otherwise buttons show! */
152 BLI_strncpy(G.lib, G.sce, FILE_MAX);
155 /* free strings of open recent files */
156 static void free_openrecent(void)
158 struct RecentFile *recent;
160 for(recent = G.recent_files.first; recent; recent=recent->next)
161 MEM_freeN(recent->filename);
163 BLI_freelistN(&(G.recent_files));
169 extern ListBase editelems;
170 extern wchar_t *copybuf;
171 extern wchar_t *copybufinfo;
173 // XXX copy/paste buffer stuff...
174 extern void free_anim_copybuf();
176 /* called in creator.c even... tsk, split this! */
177 void WM_exit(bContext *C)
181 /* first wrap up running stuff, we assume only the active WM is running */
182 /* modal handlers are on window level freed, others too? */
183 /* note; same code copied in wm_files.c */
184 if(C && CTX_wm_manager(C)) {
186 WM_jobs_stop_all(CTX_wm_manager(C));
188 for(win= CTX_wm_manager(C)->windows.first; win; win= win->next) {
190 CTX_wm_window_set(C, win); /* needed by operator close callbacks */
191 WM_event_remove_handlers(C, &win->handlers);
192 ED_screen_exit(C, win, win->screen);
195 wm_operatortype_free();
197 /* all non-screen and non-space stuff editors did, like editmode */
202 // BIF_GlobalReebFree();
203 // BIF_freeRetarget();
204 BIF_freeTemplates(C);
207 /* Context should still working here. but radio tool needs cleaning... */
208 freeAllRad(CTX_data_scene(C));
210 free_ttfont(); /* bke_font.h */
216 // if (G.background == 0)
217 // sound_end_all_sounds();
220 /* before free_blender so py's gc happens while library still exists */
221 /* needed at least for a rare sigsegv that can happen in pydrivers */
222 #ifndef DISABLE_PYTHON
226 fastshade_free_render(); /* shaded view */
227 ED_preview_free_dbase(); /* frees a Main dbase, before free_blender! */
228 free_blender(); /* blender.c, does entire library and spacetypes */
229 // free_matcopybuf();
231 // free_vertexpaint();
232 // free_imagepaint();
242 // sound_exit_audio();
243 if(G.listener) MEM_freeN(G.listener);
248 #ifdef WITH_QUICKTIME
253 // XXX UI_filelist_free_icons();
260 GPU_extensions_exit();
262 // if (copybuf) MEM_freeN(copybuf);
263 // if (copybufinfo) MEM_freeN(copybufinfo);
265 BKE_undo_save_quit(); // saves quit.blend if global undo is on
268 ED_file_exit(); /* for fsmenu */
271 BLI_freelistN(&U.themes);
277 if(MEM_get_memory_blocks_in_use()!=0) {
278 printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use());
281 // delete_autosave();
283 printf("\nBlender quit\n");
286 /* ask user to press enter when in debug mode */
288 printf("press enter key to exit...\n\n");
294 SYS_DeleteSystem(SYS_GetSystem());