soc-2008-mxcurioni: merged changes to revision 15705
[blender.git] / source / gameengine / BlenderRoutines / BL_KetsjiEmbedStart.cpp
index 4af5ac4d5d2f3a47502b6ac0f7b678a8ad8ebf11..b3a3a47152ad03a54a710f023020308a9efb4e57 100644 (file)
@@ -332,6 +332,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
                        initRasterizer(rasterizer, canvas);
                        PyObject *gameLogic = initGameLogic(startscene);
+                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
                        initGameKeys();
                        initPythonConstraintBinding();
 
@@ -399,7 +400,14 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                exitstring = ketsjiengine->GetExitString();
                                
                                // when exiting the mainloop
-                               dictionaryClearByHand(gameLogic);
+                               
+                               // Clears the dictionary by hand:
+                               // This prevents, extra references to global variables
+                               // inside the GameLogic dictionary when the python interpreter is finalized.
+                               // which allows the scene to safely delete them :)
+                               // see: (space.c)->start_game
+                               PyDict_Clear(PyModule_GetDict(gameLogic));
+                               
                                ketsjiengine->StopEngine();
                                exitGamePythonScripting();
                                networkdevice->Disconnect();
@@ -591,6 +599,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
                        initRasterizer(rasterizer, canvas);
                        PyObject *gameLogic = initGameLogic(startscene);
+                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
                        initGameKeys();
                        initPythonConstraintBinding();