From 6efd2e643953b293aaf7ef0de50d08badd2f49a8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 15 Jun 2009 20:22:50 +0000 Subject: [PATCH] saving globalDict didnt work with python3.x --- source/gameengine/Ketsji/KX_PythonInit.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 20009b7b846..b10ea7e1ab5 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1986,6 +1986,8 @@ PyObject* initGeometry() {Py_INCREF(Py_None);return Py_None;} PyObject* initBGL() {Py_INCREF(Py_None);return Py_None;} #endif + + void KX_SetActiveScene(class KX_Scene* scene) { gp_KetsjiScene = scene; @@ -2017,11 +2019,17 @@ int saveGamePythonConfig( char **marshal_buffer) if (pyGlobalDictMarshal) { // for testing only // PyObject_Print(pyGlobalDictMarshal, stderr, 0); - + char *marshal_cstring; + +#if PY_VERSION_HEX < 0x03000000 + marshal_cstring = PyString_AsString(pyGlobalDictMarshal); marshal_length= PyString_Size(pyGlobalDictMarshal); +#else // py3 uses byte arrays + marshal_cstring = PyBytes_AsString(pyGlobalDictMarshal); + marshal_length= PyBytes_Size(pyGlobalDictMarshal); +#endif *marshal_buffer = new char[marshal_length + 1]; - memcpy(*marshal_buffer, PyString_AsString(pyGlobalDictMarshal), marshal_length); - + memcpy(*marshal_buffer, marshal_cstring, marshal_length); Py_DECREF(pyGlobalDictMarshal); } else { printf("Error, GameLogic.globalDict could not be marshal'd\n");