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