Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-09-16 23:25:35 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-09-16 23:25:35 +0400
commitc6d0be2a9943818b98db3831e5d56969bd95c5fa (patch)
treeb9a870f848e0b5d7141bb6a47dbad77d746ce0c6 /source/gameengine/Ketsji/KX_PythonInit.cpp
parent75685a9ca842022519b451bea14b442f69487d9a (diff)
Fix (harmless) error print about GameLogic.globalDict being lost. Also
fixed some memory leaks in this code and simplified it.
Diffstat (limited to 'source/gameengine/Ketsji/KX_PythonInit.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 5308a0b9536..09c49a15f76 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -1393,17 +1393,21 @@ int saveGamePythonConfig( char **marshal_buffer)
PyObject* pyGlobalDictMarshal = PyMarshal_WriteObjectToString( pyGlobalDict );
#endif
if (pyGlobalDictMarshal) {
- marshal_length= PyString_Size(pyGlobalDictMarshal);
// for testing only
// PyObject_Print(pyGlobalDictMarshal, stderr, 0);
- *marshal_buffer = PyString_AsString(pyGlobalDictMarshal);
+
+ marshal_length= PyString_Size(pyGlobalDictMarshal);
+ *marshal_buffer = new char[marshal_length + 1];
+ memcpy(*marshal_buffer, PyString_AsString(pyGlobalDictMarshal), marshal_length);
+
+ Py_DECREF(pyGlobalDictMarshal);
} else {
printf("Error, GameLogic.globalDict could not be marshal'd\n");
}
- Py_DECREF(gameLogic);
} else {
printf("Error, GameLogic.globalDict was removed\n");
}
+ Py_DECREF(gameLogic);
} else {
printf("Error, GameLogic failed to import GameLogic.globalDict will be lost\n");
}
@@ -1412,20 +1416,26 @@ int saveGamePythonConfig( char **marshal_buffer)
int loadGamePythonConfig(char *marshal_buffer, int marshal_length)
{
- PyObject* gameLogic = PyImport_ImportModule("GameLogic");
/* Restore the dict */
if (marshal_buffer) {
- PyObject* pyGlobalDict = PyMarshal_ReadObjectFromString(marshal_buffer, marshal_length);
- if (pyGlobalDict) {
- PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
- return 1;
+ PyObject* gameLogic = PyImport_ImportModule("GameLogic");
+
+ if (gameLogic) {
+ PyObject* pyGlobalDict = PyMarshal_ReadObjectFromString(marshal_buffer, marshal_length);
+
+ if (pyGlobalDict) {
+ PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
+ Py_DECREF(gameLogic);
+ return 1;
+ } else {
+ Py_DECREF(gameLogic);
+ PyErr_Clear();
+ printf("Error could not marshall string\n");
+ }
} else {
- PyErr_Clear();
- printf("Error could not marshall string\n");
- }
- } else {
- printf("Error, GameLogic failed to import GameLogic.globalDict will be lost\n");
- }
+ printf("Error, GameLogic failed to import GameLogic.globalDict will be lost\n");
+ }
+ }
return 0;
}