quiet double promotion warnings for the game engine.
[blender.git] / source / gameengine / BlenderRoutines / BL_KetsjiEmbedStart.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  * Blender's Ketsji startpoint
27  */
28
29 /** \file gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
30  *  \ingroup blroutines
31  */
32
33
34 #include <signal.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37
38 #if defined(WIN32) && !defined(FREE_WINDOWS)
39 // don't show stl-warnings
40 #pragma warning (disable:4786)
41 #endif
42
43 #include "GL/glew.h"
44
45 #include "KX_BlenderGL.h"
46 #include "KX_BlenderCanvas.h"
47 #include "KX_BlenderKeyboardDevice.h"
48 #include "KX_BlenderMouseDevice.h"
49 #include "KX_BlenderRenderTools.h"
50 #include "KX_BlenderSystem.h"
51 #include "BL_Material.h"
52
53 #include "KX_KetsjiEngine.h"
54 #include "KX_BlenderSceneConverter.h"
55 #include "KX_PythonInit.h"
56 #include "KX_PyConstraintBinding.h"
57
58 #include "RAS_GLExtensionManager.h"
59 #include "RAS_OpenGLRasterizer.h"
60 #include "RAS_VAOpenGLRasterizer.h"
61 #include "RAS_ListRasterizer.h"
62
63 #include "NG_LoopBackNetworkDeviceInterface.h"
64
65 #include "BL_System.h"
66
67 #include "GPU_extensions.h"
68 #include "Value.h"
69
70
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75         /***/
76 #include "DNA_view3d_types.h"
77 #include "DNA_screen_types.h"
78 #include "DNA_userdef_types.h"
79 #include "DNA_windowmanager_types.h"
80 #include "BKE_global.h"
81 #include "BKE_report.h"
82 /* #include "BKE_screen.h" */ /* cant include this because of 'new' function name */
83 extern float BKE_screen_view3d_zoom_to_fac(float camzoom);
84
85 #include "BKE_main.h"
86 #include "BLI_blenlib.h"
87 #include "BLO_readfile.h"
88 #include "DNA_scene_types.h"
89 #include "BKE_ipo.h"
90         /***/
91
92 #include "BKE_context.h"
93 #include "../../blender/windowmanager/WM_types.h"
94 #include "../../blender/windowmanager/wm_window.h"
95 #include "../../blender/windowmanager/wm_event_system.h"
96 #ifdef __cplusplus
97 }
98 #endif
99
100 #ifdef WITH_AUDASPACE
101 #  include "AUD_C-API.h"
102 #  include "AUD_I3DDevice.h"
103 #  include "AUD_IDevice.h"
104 #endif
105
106 static BlendFileData *load_game_data(char *filename)
107 {
108         ReportList reports;
109         BlendFileData *bfd;
110         
111         BKE_reports_init(&reports, RPT_STORE);
112         bfd= BLO_read_from_file(filename, &reports);
113
114         if (!bfd) {
115                 printf("Loading %s failed: ", filename);
116                 BKE_reports_print(&reports, RPT_ERROR);
117         }
118
119         BKE_reports_clear(&reports);
120
121         return bfd;
122 }
123
124 extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *cam_frame, int always_use_expand_framing)
125 {
126         /* context values */
127         struct wmWindow *win= CTX_wm_window(C);
128         struct Scene *startscene= CTX_data_scene(C);
129         struct Main* maggie1= CTX_data_main(C);
130
131
132         RAS_Rect area_rect;
133         area_rect.SetLeft(cam_frame->xmin);
134         area_rect.SetBottom(cam_frame->ymin);
135         area_rect.SetRight(cam_frame->xmax);
136         area_rect.SetTop(cam_frame->ymax);
137
138         int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
139         Main* blenderdata = maggie1;
140
141         char* startscenename = startscene->id.name+2;
142         char pathname[FILE_MAXDIR+FILE_MAXFILE], oldsce[FILE_MAXDIR+FILE_MAXFILE];
143         STR_String exitstring = "";
144         BlendFileData *bfd= NULL;
145
146         BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
147         BLI_strncpy(oldsce, G.main->name, sizeof(oldsce));
148 #ifdef WITH_PYTHON
149         resetGamePythonPath(); // need this so running a second time wont use an old blendfiles path
150         setGamePythonPath(G.main->name);
151
152         // Acquire Python's GIL (global interpreter lock)
153         // so we can safely run Python code and API calls
154         PyGILState_STATE gilstate = PyGILState_Ensure();
155         
156         PyObject *pyGlobalDict = PyDict_New(); /* python utility storage, spans blend file loading */
157 #endif
158         
159         bgl::InitExtensions(true);
160
161         // VBO code for derived mesh is not compatible with BGE (couldn't find why), so disable
162         int disableVBO = (U.gameflags & USER_DISABLE_VBO);
163         U.gameflags |= USER_DISABLE_VBO;
164
165         // Globals to be carried on over blender files
166         GlobalSettings gs;
167         gs.matmode= startscene->gm.matmode;
168         gs.glslflag= startscene->gm.flag;
169
170         do
171         {
172                 View3D *v3d= CTX_wm_view3d(C);
173                 RegionView3D *rv3d= CTX_wm_region_view3d(C);
174
175                 // get some preferences
176                 SYS_SystemHandle syshandle = SYS_GetSystem();
177                 bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
178                 bool usefixed = (SYS_GetCommandLineInt(syshandle, "fixedtime", 0) != 0);
179                 bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
180                 bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
181                 bool animation_record = (SYS_GetCommandLineInt(syshandle, "animation_record", 0) != 0);
182                 bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0);
183 #ifdef WITH_PYTHON
184                 bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 0) != 0);
185 #endif
186                 bool novertexarrays = (SYS_GetCommandLineInt(syshandle, "novertexarrays", 0) != 0);
187                 bool mouse_state = startscene->gm.flag & GAME_SHOW_MOUSE;
188                 bool restrictAnimFPS = startscene->gm.flag & GAME_RESTRICT_ANIM_UPDATES;
189
190                 if (animation_record) usefixed= false; /* override since you don't want to run full-speed for sim recording */
191
192                 // create the canvas, rasterizer and rendertools
193                 RAS_ICanvas* canvas = new KX_BlenderCanvas(win, area_rect, ar);
194                 
195                 // default mouse state set on render panel
196                 if (mouse_state)
197                         canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
198                 else
199                         canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
200                 RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
201                 RAS_IRasterizer* rasterizer = NULL;
202                 
203                 if (displaylists) {
204                         if (GLEW_VERSION_1_1 && !novertexarrays)
205                                 rasterizer = new RAS_ListRasterizer(canvas, true, true);
206                         else
207                                 rasterizer = new RAS_ListRasterizer(canvas);
208                 }
209                 else if (GLEW_VERSION_1_1 && !novertexarrays)
210                         rasterizer = new RAS_VAOpenGLRasterizer(canvas, false);
211                 else
212                         rasterizer = new RAS_OpenGLRasterizer(canvas);
213                 
214                 // create the inputdevices
215                 KX_BlenderKeyboardDevice* keyboarddevice = new KX_BlenderKeyboardDevice();
216                 KX_BlenderMouseDevice* mousedevice = new KX_BlenderMouseDevice();
217                 
218                 // create a networkdevice
219                 NG_NetworkDeviceInterface* networkdevice = new
220                         NG_LoopBackNetworkDeviceInterface();
221
222                 //
223                 // create a ketsji/blendersystem (only needed for timing and stuff)
224                 KX_BlenderSystem* kxsystem = new KX_BlenderSystem();
225                 
226                 // create the ketsjiengine
227                 KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem);
228                 
229                 // set the devices
230                 ketsjiengine->SetKeyboardDevice(keyboarddevice);
231                 ketsjiengine->SetMouseDevice(mousedevice);
232                 ketsjiengine->SetNetworkDevice(networkdevice);
233                 ketsjiengine->SetCanvas(canvas);
234                 ketsjiengine->SetRenderTools(rendertools);
235                 ketsjiengine->SetRasterizer(rasterizer);
236                 ketsjiengine->SetUseFixedTime(usefixed);
237                 ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
238                 ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
239                 KX_KetsjiEngine::SetExitKey(ConvertKeyCode(startscene->gm.exitkey));
240
241                 //set the global settings (carried over if restart/load new files)
242                 ketsjiengine->SetGlobalSettings(&gs);
243
244 #ifdef WITH_PYTHON
245                 CValue::SetDeprecationWarnings(nodepwarnings);
246 #endif
247
248                 //lock frame and camera enabled - storing global values
249                 int tmp_lay= startscene->lay;
250                 Object *tmp_camera = startscene->camera;
251
252                 if (v3d->scenelock==0) {
253                         startscene->lay= v3d->lay;
254                         startscene->camera= v3d->camera;
255                 }
256
257                 // some blender stuff
258                 float camzoom;
259                 int draw_letterbox = 0;
260                 
261                 if (rv3d->persp==RV3D_CAMOB) {
262                         if (startscene->gm.framing.type == SCE_GAMEFRAMING_BARS) { /* Letterbox */
263                                 camzoom = 1.0f;
264                                 draw_letterbox = 1;
265                         }
266                         else {
267                                 camzoom = 1.0f / BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
268                         }
269                 }
270                 else {
271                         camzoom = 2.0;
272                 }
273
274
275                 ketsjiengine->SetDrawType(v3d->drawtype);
276                 ketsjiengine->SetCameraZoom(camzoom);
277                 
278                 // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
279                 if (exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME || exitrequested == KX_EXIT_REQUEST_RESTART_GAME)
280                 {
281                         exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
282                         if (bfd) BLO_blendfiledata_free(bfd);
283                         
284                         char basedpath[FILE_MAX];
285                         // base the actuator filename with respect
286                         // to the original file working directory
287
288                         if (exitstring != "")
289                                 strcpy(basedpath, exitstring.Ptr());
290
291                         // load relative to the last loaded file, this used to be relative
292                         // to the first file but that makes no sense, relative paths in
293                         // blend files should be relative to that file, not some other file
294                         // that happened to be loaded first
295                         BLI_path_abs(basedpath, pathname);
296                         bfd = load_game_data(basedpath);
297                         
298                         // if it wasn't loaded, try it forced relative
299                         if (!bfd)
300                         {
301                                 // just add "//" in front of it
302                                 char temppath[242];
303                                 strcpy(temppath, "//");
304                                 strcat(temppath, basedpath);
305                                 
306                                 BLI_path_abs(temppath, pathname);
307                                 bfd = load_game_data(temppath);
308                         }
309                         
310                         // if we got a loaded blendfile, proceed
311                         if (bfd)
312                         {
313                                 blenderdata = bfd->main;
314                                 startscenename = bfd->curscene->id.name + 2;
315
316                                 if (blenderdata) {
317                                         BLI_strncpy(G.main->name, blenderdata->name, sizeof(G.main->name));
318                                         BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
319 #ifdef WITH_PYTHON
320                                         setGamePythonPath(G.main->name);
321 #endif
322                                 }
323                         }
324                         // else forget it, we can't find it
325                         else
326                         {
327                                 exitrequested = KX_EXIT_REQUEST_QUIT_GAME;
328                         }
329                 }
330
331                 Scene *scene= bfd ? bfd->curscene : (Scene *)BLI_findstring(&blenderdata->scene, startscenename, offsetof(ID, name) + 2);
332
333                 if (scene)
334                 {
335                         int startFrame = scene->r.cfra;
336                         ketsjiengine->SetAnimRecordMode(animation_record, startFrame);
337                         
338                         // Quad buffered needs a special window.
339                         if (scene->gm.stereoflag == STEREO_ENABLED) {
340                                 if (scene->gm.stereomode != RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
341                                         rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) scene->gm.stereomode);
342
343                                 rasterizer->SetEyeSeparation(scene->gm.eyeseparation);
344                         }
345
346                         rasterizer->SetBackColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 0.0f);
347                 }
348                 
349                 if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME)
350                 {
351                         if (rv3d->persp != RV3D_CAMOB)
352                         {
353                                 ketsjiengine->EnableCameraOverride(startscenename);
354                                 ketsjiengine->SetCameraOverrideUseOrtho((rv3d->persp == RV3D_ORTHO));
355                                 ketsjiengine->SetCameraOverrideProjectionMatrix(MT_CmMatrix4x4(rv3d->winmat));
356                                 ketsjiengine->SetCameraOverrideViewMatrix(MT_CmMatrix4x4(rv3d->viewmat));
357                                 if (rv3d->persp == RV3D_ORTHO)
358                                 {
359                                         ketsjiengine->SetCameraOverrideClipping(-v3d->far, v3d->far);
360                                 }
361                                 else
362                                 {
363                                         ketsjiengine->SetCameraOverrideClipping(v3d->near, v3d->far);
364                                 }
365                                 ketsjiengine->SetCameraOverrideLens(v3d->lens);
366                         }
367                         
368                         // create a scene converter, create and convert the startingscene
369                         KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata, ketsjiengine);
370                         ketsjiengine->SetSceneConverter(sceneconverter);
371                         sceneconverter->addInitFromFrame=false;
372                         if (always_use_expand_framing)
373                                 sceneconverter->SetAlwaysUseExpandFraming(true);
374
375                         bool usemat = false, useglslmat = false;
376
377                         if (GLEW_ARB_multitexture && GLEW_VERSION_1_1)
378                                 usemat = true;
379
380                         if (GPU_glsl_support())
381                                 useglslmat = true;
382                         else if (gs.matmode == GAME_MAT_GLSL)
383                                 usemat = false;
384
385                         if (usemat && (gs.matmode != GAME_MAT_TEXFACE))
386                                 sceneconverter->SetMaterials(true);
387                         if (useglslmat && (gs.matmode == GAME_MAT_GLSL))
388                                 sceneconverter->SetGLSLMaterials(true);
389                                         
390                         KX_Scene* startscene = new KX_Scene(keyboarddevice,
391                                 mousedevice,
392                                 networkdevice,
393                                 startscenename,
394                                 scene,
395                                 canvas);
396
397 #ifdef WITH_PYTHON
398                         // some python things
399                         PyObject *gameLogic, *gameLogic_keys;
400                         setupGamePython(ketsjiengine, startscene, blenderdata, pyGlobalDict, &gameLogic, &gameLogic_keys, 0, NULL);
401 #endif // WITH_PYTHON
402
403                         //initialize Dome Settings
404                         if (scene->gm.stereoflag == STEREO_DOME)
405                                 ketsjiengine->InitDome(scene->gm.dome.res, scene->gm.dome.mode, scene->gm.dome.angle, scene->gm.dome.resbuf, scene->gm.dome.tilt, scene->gm.dome.warptext);
406
407                         // initialize 3D Audio Settings
408                         AUD_I3DDevice* dev = AUD_get3DDevice();
409                         if (dev)
410                         {
411                                 dev->setSpeedOfSound(scene->audio.speed_of_sound);
412                                 dev->setDopplerFactor(scene->audio.doppler_factor);
413                                 dev->setDistanceModel(AUD_DistanceModel(scene->audio.distance_model));
414                         }
415
416                         // from see blender.c:
417                         // FIXME: this version patching should really be part of the file-reading code,
418                         // but we still get too many unrelated data-corruption crashes otherwise...
419                         if (blenderdata->versionfile < 250)
420                                 do_versions_ipos_to_animato(blenderdata);
421
422                         if (sceneconverter)
423                         {
424                                 // convert and add scene
425                                 sceneconverter->ConvertScene(
426                                         startscene,
427                                         rendertools,
428                                         canvas);
429                                 ketsjiengine->AddScene(startscene);
430                                 
431                                 // init the rasterizer
432                                 rasterizer->Init();
433                                 
434                                 // start the engine
435                                 ketsjiengine->StartEngine(true);
436                                 
437
438                                 // Set the animation playback rate for ipo's and actions
439                                 // the framerate below should patch with FPS macro defined in blendef.h
440                                 // Could be in StartEngine set the framerate, we need the scene to do this
441                                 ketsjiengine->SetAnimFrameRate(FPS);
442                                 
443                                 // the mainloop
444                                 printf("\nBlender Game Engine Started\n");
445                                 while (!exitrequested)
446                                 {
447                                         // first check if we want to exit
448                                         exitrequested = ketsjiengine->GetExitCode();
449                                         
450                                         // kick the engine
451                                         bool render = ketsjiengine->NextFrame();
452                                         
453                                         if (render)
454                                         {
455                                                 if (draw_letterbox) {
456                                                         // Clear screen to border color
457                                                         // We do this here since we set the canvas to be within the frames. This means the engine
458                                                         // itself is unaware of the extra space, so we clear the whole region for it.
459                                                         glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f);
460                                                         glViewport(ar->winrct.xmin, ar->winrct.ymin,
461                                                                 ar->winrct.xmax - ar->winrct.xmin, ar->winrct.ymax - ar->winrct.ymin);
462                                                         glClear(GL_COLOR_BUFFER_BIT);
463                                                 }
464
465                                                 // render the frame
466                                                 ketsjiengine->Render();
467                                         }
468                                         
469                                         wm_window_process_events_nosleep();
470                                         
471                                         // test for the ESC key
472                                         //XXX while (qtest())
473                                         while(wmEvent *event= (wmEvent *)win->queue.first)
474                                         {
475                                                 short val = 0;
476                                                 //unsigned short event = 0; //XXX extern_qread(&val);
477                                                 
478                                                 if (keyboarddevice->ConvertBlenderEvent(event->type,event->val))
479                                                         exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
480                                                 
481                                                         /* Coordinate conversion... where
482                                                         * should this really be?
483                                                 */
484                                                 if (event->type==MOUSEMOVE) {
485                                                         /* Note, not nice! XXX 2.5 event hack */
486                                                         val = event->x - ar->winrct.xmin;
487                                                         mousedevice->ConvertBlenderEvent(MOUSEX, val);
488                                                         
489                                                         val = ar->winy - (event->y - ar->winrct.ymin) - 1;
490                                                         mousedevice->ConvertBlenderEvent(MOUSEY, val);
491                                                 }
492                                                 else {
493                                                         mousedevice->ConvertBlenderEvent(event->type,event->val);
494                                                 }
495                                                 
496                                                 BLI_remlink(&win->queue, event);
497                                                 wm_event_free(event);
498                                         }
499                                         
500                                         if (win != CTX_wm_window(C)) {
501                                                 exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */
502                                         }
503                                 }
504                                 printf("Blender Game Engine Finished\n");
505                                 exitstring = ketsjiengine->GetExitString();
506                                 gs = *(ketsjiengine->GetGlobalSettings());
507
508
509                                 // when exiting the mainloop
510 #ifdef WITH_PYTHON
511                                 // Clears the dictionary by hand:
512                                 // This prevents, extra references to global variables
513                                 // inside the GameLogic dictionary when the python interpreter is finalized.
514                                 // which allows the scene to safely delete them :)
515                                 // see: (space.c)->start_game
516                                 
517                                 //PyDict_Clear(PyModule_GetDict(gameLogic));
518                                 
519                                 // Keep original items, means python plugins will autocomplete members
520                                 PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic));
521                                 const Py_ssize_t numitems= PyList_GET_SIZE(gameLogic_keys_new);
522                                 Py_ssize_t listIndex;
523                                 for (listIndex=0; listIndex < numitems; listIndex++)  {
524                                         PyObject* item = PyList_GET_ITEM(gameLogic_keys_new, listIndex);
525                                         if (!PySequence_Contains(gameLogic_keys, item)) {
526                                                 PyDict_DelItem( PyModule_GetDict(gameLogic), item);
527                                         }
528                                 }
529                                 Py_DECREF(gameLogic_keys_new);
530                                 gameLogic_keys_new = NULL;
531 #endif
532                                 ketsjiengine->StopEngine();
533 #ifdef WITH_PYTHON
534                                 exitGamePythonScripting();
535 #endif
536                                 networkdevice->Disconnect();
537                         }
538                         if (sceneconverter)
539                         {
540                                 delete sceneconverter;
541                                 sceneconverter = NULL;
542                         }
543
544 #ifdef WITH_PYTHON
545                         Py_DECREF(gameLogic_keys);
546                         gameLogic_keys = NULL;
547 #endif
548                 }
549                 //lock frame and camera enabled - restoring global values
550                 if (v3d->scenelock==0) {
551                         startscene->lay= tmp_lay;
552                         startscene->camera= tmp_camera;
553                 }
554
555                 if (exitrequested != KX_EXIT_REQUEST_OUTSIDE)
556                 {
557                         // set the cursor back to normal
558                         canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
559                 }
560                 
561                 // clean up some stuff
562                 if (ketsjiengine)
563                 {
564                         delete ketsjiengine;
565                         ketsjiengine = NULL;
566                 }
567                 if (kxsystem)
568                 {
569                         delete kxsystem;
570                         kxsystem = NULL;
571                 }
572                 if (networkdevice)
573                 {
574                         delete networkdevice;
575                         networkdevice = NULL;
576                 }
577                 if (keyboarddevice)
578                 {
579                         delete keyboarddevice;
580                         keyboarddevice = NULL;
581                 }
582                 if (mousedevice)
583                 {
584                         delete mousedevice;
585                         mousedevice = NULL;
586                 }
587                 if (rasterizer)
588                 {
589                         delete rasterizer;
590                         rasterizer = NULL;
591                 }
592                 if (rendertools)
593                 {
594                         delete rendertools;
595                         rendertools = NULL;
596                 }
597                 if (canvas)
598                 {
599                         delete canvas;
600                         canvas = NULL;
601                 }
602
603                 // stop all remaining playing sounds
604                 AUD_getDevice()->stopAll();
605         
606         } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
607         
608         if (!disableVBO)
609                 U.gameflags &= ~USER_DISABLE_VBO;
610
611         if (bfd) BLO_blendfiledata_free(bfd);
612
613         BLI_strncpy(G.main->name, oldsce, sizeof(G.main->name));
614
615 #ifdef WITH_PYTHON
616         Py_DECREF(pyGlobalDict);
617
618         // Release Python's GIL
619         PyGILState_Release(gilstate);
620 #endif
621
622 }