BGE: Fix T48071: Global logic manager
authorPorteries Tristan <republicthunderbolt9@gmail.com>
Sun, 10 Apr 2016 15:36:10 +0000 (17:36 +0200)
committerPorteries Tristan <republicthunderbolt9@gmail.com>
Sun, 10 Apr 2016 21:57:43 +0000 (23:57 +0200)
Previously the logic manager was used as a global variable for SCA_ILogicBrick::m_sCurrentLogicManager,
this request to always update it before run any python script and allow call function like
ConvertPythonTo[GameObject/Mesh]. The bug showed in T48071 is that as exepted the global
m_sCurrentLogicManager is not updated with the proper scene logic manager.
Instead of trying to fix it by updating the logic manager everywhere and wait next bug report to add
a similar line. The following patch propose a different way:
- Every logic brick now contain its logic manager to SCA_ILogicBrick::m_logicManager, this value is
  set and get by SCA_ILogicBrick::[Set/Get]LogicManager, It's initialized from blender conversion and
  scene merging.
- Function ConvertPythonTo[GameObject/mesh] now take as first argument the logic manager to find name
  coresponding object or mesh. Only ConvertPythonToCamera doesn't do that because it uses the
  KX_Scene::FindCamera function.

Reviewers: moguri

Differential Revision: https://developer.blender.org/D1913

25 files changed:
source/gameengine/Converter/BL_ActionActuator.cpp
source/gameengine/Converter/BL_ArmatureActuator.cpp
source/gameengine/Converter/BL_ArmatureConstraint.cpp
source/gameengine/Converter/BL_ShapeActionActuator.cpp
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/Converter/KX_ConvertControllers.cpp
source/gameengine/Converter/KX_ConvertSensors.cpp
source/gameengine/GameLogic/SCA_ILogicBrick.cpp
source/gameengine/GameLogic/SCA_ILogicBrick.h
source/gameengine/GameLogic/SCA_PythonController.cpp
source/gameengine/Ketsji/KX_Camera.cpp
source/gameengine/Ketsji/KX_CameraActuator.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_MeshProxy.cpp
source/gameengine/Ketsji/KX_MeshProxy.h
source/gameengine/Ketsji/KX_ObjectActuator.cpp
source/gameengine/Ketsji/KX_ParentActuator.cpp
source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_SteeringActuator.cpp
source/gameengine/Ketsji/KX_TrackToActuator.cpp
source/gameengine/Ketsji/KX_VehicleWrapper.cpp

index d9865c1f4fbee800d59fdc0bb7b08e885326d614..d28cdb84275a94b1736254ce7e9a032c05f4c2a6 100644 (file)
@@ -584,7 +584,7 @@ int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF
        
        if (val != "")
        {
-               action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
+               action= (bAction*)self->GetLogicManager()->GetActionByName(val);
                if (!action)
                {
                        PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
index e38cb6eadaf3a49651245594ac609706ab3d00cd..67cc7d2c291414b9de0a2151d2c8d269e03122e5 100644 (file)
@@ -243,7 +243,7 @@ int BL_ArmatureActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBU
        KX_GameObject* &target = (!strcmp(attrdef->m_name, "target")) ? actuator->m_gametarget : actuator->m_gamesubtarget;
        KX_GameObject *gameobj;
                
-       if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: BL_ArmatureActuator"))
+       if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: BL_ArmatureActuator"))
                return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
                
        if (target != NULL)
index 88d82e21d6196451ea82b4b6373c43f8367438cd..d0c7e061fb781d2afbff34ba48388b870aaf5ec1 100644 (file)
@@ -36,6 +36,7 @@
 #include "BL_ArmatureObject.h"
 #include "BLI_math.h"
 #include "BLI_string.h"
+#include "KX_PythonInit.h"
 
 #ifdef WITH_PYTHON
 
@@ -360,6 +361,7 @@ int BL_ArmatureConstraint::py_attr_setattr(void *self_v, const struct KX_PYATTRI
        int ival;
        double dval;
 //     char* sval;
+       SCA_LogicManager *logicmgr = KX_GetActiveScene()->GetLogicManager();
        KX_GameObject *oval;
 
        if (!constraint) {
@@ -387,13 +389,13 @@ int BL_ArmatureConstraint::py_attr_setattr(void *self_v, const struct KX_PYATTRI
                return PY_SET_ATTR_SUCCESS;
 
        case BCA_TARGET:
-               if (!ConvertPythonToGameObject(value, &oval, true, "constraint.target = value: BL_ArmatureConstraint"))
+               if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.target = value: BL_ArmatureConstraint"))
                        return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
                self->SetTarget(oval);
                return PY_SET_ATTR_SUCCESS;
 
        case BCA_SUBTARGET:
-               if (!ConvertPythonToGameObject(value, &oval, true, "constraint.subtarget = value: BL_ArmatureConstraint"))
+               if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.subtarget = value: BL_ArmatureConstraint"))
                        return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
                self->SetSubtarget(oval);
                return PY_SET_ATTR_SUCCESS;
index e8f451213f5ee44904347a5e5b032d97123c9965..f21db419ebc5208f9760544ac6f040389664058c 100644 (file)
@@ -547,7 +547,7 @@ int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE
        
        if (val != "")
        {
-               action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
+               action= (bAction*)self->GetLogicManager()->GetActionByName(val);
                if (action==NULL)
                {
                        PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, action not found!");
index 021111b4fe5cd0a840e62b56b067f2c80093cb0f..455fef0aceb257b2bde7ac19948e3aeb9bb8f77d 100644 (file)
@@ -1127,6 +1127,7 @@ void BL_ConvertActuators(const char* maggiename,
                        uniquename += uniqueval->GetText();
                        uniqueval->Release();
                        baseact->SetName(bact->name);
+                       baseact->SetLogicManager(logicmgr);
                        //gameobj->SetProperty(uniquename,baseact);
                        gameobj->AddActuator(baseact);
                        
index e3697087ea9ab8101b88d58f624c2e414f2134b9..f55d81adb802dbf64d2f8ecc204eb8b68cd6da97 100644 (file)
@@ -214,6 +214,7 @@ void BL_ConvertControllers(
                        //at some point it should either be implemented globally (and saved as a separate var) or removed.
                        //gamecontroller->SetName(uniquename);
                        gamecontroller->SetName(bcontr->name);
+                       gamecontroller->SetLogicManager(logicmgr);
                        gameobj->AddController(gamecontroller);
                        
                        converter->RegisterGameController(gamecontroller, bcontr);
index 79fd9cb925497d5608d873afbc765757e4ee4a67..5e897bb4a623383c4313fa4242b27243fb37539d 100644 (file)
@@ -608,6 +608,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                gamesensor->SetLevel(level);
                                gamesensor->SetTap(tap);
                                gamesensor->SetName(sens->name);
+                               gamesensor->SetLogicManager(logicmgr);
 
                                gameobj->AddSensor(gamesensor);
 
index 72a0b392447f159f103f2f6967459fa4ec6aeb17..d0a6e4540c9011dc9346cbdd6c3c986e531b312e 100644 (file)
 #include "SCA_ILogicBrick.h"
 #include "EXP_PyObjectPlus.h"
 
-SCA_LogicManager* SCA_ILogicBrick::m_sCurrentLogicManager = NULL;
-
 SCA_ILogicBrick::SCA_ILogicBrick(SCA_IObject* gameobj)
        :
        CValue(),
        m_gameobj(gameobj),
+       m_logicManager(NULL),
        m_Execute_Priority(0),
        m_Execute_Ueber_Priority(0),
        m_bActive(false),
@@ -143,6 +142,16 @@ bool SCA_ILogicBrick::LessComparedTo(SCA_ILogicBrick* other)
                (this->m_Execute_Priority < other->m_Execute_Priority));
 }
 
+void SCA_ILogicBrick::SetLogicManager(SCA_LogicManager *logicmgr)
+{
+       m_logicManager = logicmgr;
+}
+
+SCA_LogicManager *SCA_ILogicBrick::GetLogicManager()
+{
+       return m_logicManager;
+}
+
 void SCA_ILogicBrick::RegisterEvent(CValue* eventval)
 {
        if (m_eventval)
index a37257892276654caf286d88aaa2873620a0fbff..f9ef18cc3486da1d6b9246062be2751e2347de5f 100644 (file)
 
 class NG_NetworkScene;
 class SCA_IScene;
+class SCA_LogicManager;
 
 class SCA_ILogicBrick : public CValue
 {
        Py_Header
 protected:
        SCA_IObject*            m_gameobj;
+       SCA_LogicManager *m_logicManager;
        int                                     m_Execute_Priority;
        int                                     m_Execute_Ueber_Priority;
 
@@ -127,9 +129,8 @@ public:
 
        virtual bool            LessComparedTo(SCA_ILogicBrick* other);
 
-       /* runtime variable, set when Triggering the python controller */
-       static class SCA_LogicManager*  m_sCurrentLogicManager;
-
+       virtual void SetLogicManager(SCA_LogicManager *logicmgr);
+       SCA_LogicManager *GetLogicManager();
 
        /* for moving logic bricks between scenes */
        virtual void            Replace_IScene(SCA_IScene *val) {}
index fa30e3a5caff4607b2373077d5ea1c26eb9570bf..25936b34fde9996ac0702d3f96e00b1cc80afa59 100644 (file)
@@ -386,8 +386,7 @@ bool SCA_PythonController::Import()
 void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
 {
        m_sCurrentController = this;
-       m_sCurrentLogicManager = logicmgr;
-       
+
        PyObject *excdict=              NULL;
        PyObject *resultobj=    NULL;
        
@@ -478,7 +477,7 @@ PyObject *SCA_PythonController::PyActivate(PyObject *value)
        if (actu==NULL)
                return NULL;
        
-       m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, true);
+       m_logicManager->AddActiveActuator((SCA_IActuator*)actu, true);
        Py_RETURN_NONE;
 }
 
@@ -493,7 +492,7 @@ PyObject *SCA_PythonController::PyDeActivate(PyObject *value)
        if (actu==NULL)
                return NULL;
        
-       m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, false);
+       m_logicManager->AddActiveActuator((SCA_IActuator*)actu, false);
        Py_RETURN_NONE;
 }
 
index 361cd65d50a2a97a73791869ea360b84f7f82068..89aea80bb677007508c1282a14df84fad2cb5cca 100644 (file)
@@ -1035,7 +1035,7 @@ KX_PYMETHODDEF_DOC_O(KX_Camera, getScreenPosition,
        {
                PyErr_Clear();
 
-               if (ConvertPythonToGameObject(value, &obj, true, ""))
+               if (ConvertPythonToGameObject(GetScene()->GetLogicManager(), value, &obj, true, ""))
                {
                        PyErr_Clear();
                        vect = MT_Vector3(obj->NodeGetWorldPosition());
index f065e3f0001c7ad8a064b8d64846938ffa2fd0fc..e488bf3c30a50b544881b9fe0805990674f81096 100644 (file)
@@ -411,7 +411,7 @@ int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF
        KX_CameraActuator* self = static_cast<KX_CameraActuator*>(self_v);
        KX_GameObject *gameobj;
        
-       if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_CameraActuator"))
+       if (!ConvertPythonToGameObject(self->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_CameraActuator"))
                return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
        
        if (self->m_ob)
index 877e95885a229ebce589d5d16b8efb63deb7e262..69c1af35bd9d59fa94890e6db4f20b4b138cc718 100644 (file)
@@ -1597,14 +1597,6 @@ void KX_GameObject::RunCollisionCallbacks(KX_GameObject *collider, const MT_Vect
        if (!m_collisionCallbacks || PyList_GET_SIZE(m_collisionCallbacks) == 0)
                return;
 
-       /** Current logic controller is set by each python logic bricks before run,
-        * but if no python logic brick ran the logic manager can be wrong 
-        * (if the user use muti scenes) and it will cause problems with function
-        * ConvertPythonToGameObject which use the current logic manager for object's name.
-        * Note: the scene is already set in logic frame loop.
-        */
-       SCA_ILogicBrick::m_sCurrentLogicManager = GetScene()->GetLogicManager();
-
        PyObject *args[] = {collider->GetProxy(), PyObjectFrom(point), PyObjectFrom(normal)};
        RunPythonCallBackList(m_collisionCallbacks, args, 1, ARRAY_SIZE(args));
 
@@ -2043,7 +2035,8 @@ PyAttributeDef KX_GameObject::Attributes[] = {
 PyObject *KX_GameObject::PyReplaceMesh(PyObject *args)
 {
        KX_Scene *scene = KX_GetActiveScene();
-       
+       SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
+
        PyObject *value;
        int use_gfx= 1, use_phys= 0;
        RAS_MeshObject *new_mesh;
@@ -2051,7 +2044,7 @@ PyObject *KX_GameObject::PyReplaceMesh(PyObject *args)
        if (!PyArg_ParseTuple(args,"O|ii:replaceMesh", &value, &use_gfx, &use_phys))
                return NULL;
        
-       if (!ConvertPythonToMesh(value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject"))
+       if (!ConvertPythonToMesh(logicmgr, value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject"))
                return NULL;
        
        scene->ReplaceMesh(this, new_mesh, (bool)use_gfx, (bool)use_phys);
@@ -2072,13 +2065,14 @@ PyObject *KX_GameObject::PyReinstancePhysicsMesh(PyObject *args)
 {
        KX_GameObject *gameobj= NULL;
        RAS_MeshObject *mesh= NULL;
+       SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
        
        PyObject *gameobj_py= NULL;
        PyObject *mesh_py= NULL;
 
        if (    !PyArg_ParseTuple(args,"|OO:reinstancePhysicsMesh",&gameobj_py, &mesh_py) ||
-                       (gameobj_py && !ConvertPythonToGameObject(gameobj_py, &gameobj, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject")) || 
-                       (mesh_py && !ConvertPythonToMesh(mesh_py, &mesh, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject"))
+                       (gameobj_py && !ConvertPythonToGameObject(logicmgr, gameobj_py, &gameobj, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject")) || 
+                       (mesh_py && !ConvertPythonToMesh(logicmgr, mesh_py, &mesh, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject"))
                ) {
                return NULL;
        }
@@ -3423,6 +3417,7 @@ PyObject *KX_GameObject::PyDisableRigidBody()
 PyObject *KX_GameObject::PySetParent(PyObject *args)
 {
        KX_Scene *scene = KX_GetActiveScene();
+       SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
        PyObject *pyobj;
        KX_GameObject *obj;
        int addToCompound=1, ghost=1;
@@ -3430,7 +3425,7 @@ PyObject *KX_GameObject::PySetParent(PyObject *args)
        if (!PyArg_ParseTuple(args,"O|ii:setParent", &pyobj, &addToCompound, &ghost)) {
                return NULL; // Python sets a simple error
        }
-       if (!ConvertPythonToGameObject(pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
+       if (!ConvertPythonToGameObject(logicmgr, pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
                return NULL;
        if (obj)
                this->SetParent(scene, obj, addToCompound, ghost);
@@ -3586,9 +3581,10 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getDistanceTo,
                return PyFloat_FromDouble(NodeGetWorldPosition().distance(b));
        }
        PyErr_Clear();
-       
+
+       SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
        KX_GameObject *other;
-       if (ConvertPythonToGameObject(value, &other, false, "gameOb.getDistanceTo(value): KX_GameObject"))
+       if (ConvertPythonToGameObject(logicmgr, value, &other, false, "gameOb.getDistanceTo(value): KX_GameObject"))
        {
                return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition()));
        }
@@ -3604,6 +3600,7 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo,
        MT_Vector3 toDir, locToDir;
        MT_Scalar distance;
 
+       SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
        PyObject *returnValue;
 
        if (!PyVecTo(value, toPoint))
@@ -3611,7 +3608,7 @@ KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo,
                PyErr_Clear();
                
                KX_GameObject *other;
-               if (ConvertPythonToGameObject(value, &other, false, "")) /* error will be overwritten */
+               if (ConvertPythonToGameObject(logicmgr, value, &other, false, "")) /* error will be overwritten */
                {
                        toPoint = other->NodeGetWorldPosition();
                } else
@@ -3713,6 +3710,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
        PyObject *pyarg;
        float dist = 0.0f;
        char *propName = NULL;
+       SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
 
        if (!PyArg_ParseTuple(args,"O|fs:rayCastTo", &pyarg, &dist, &propName)) {
                return NULL; // python sets simple error
@@ -3723,7 +3721,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
                KX_GameObject *other;
                PyErr_Clear();
                
-               if (ConvertPythonToGameObject(pyarg, &other, false, "")) /* error will be overwritten */
+               if (ConvertPythonToGameObject(logicmgr, pyarg, &other, false, "")) /* error will be overwritten */
                {
                        toPoint = other->NodeGetWorldPosition();
                } else
@@ -3829,6 +3827,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
        KX_GameObject *other;
        int face=0, xray=0, poly=0;
        int mask = (1 << OB_MAX_COL_MASKS) - 1;
+       SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
 
        if (!PyArg_ParseTuple(args,"O|Ofsiiii:rayCast", &pyto, &pyfrom, &dist, &propName, &face, &xray, &poly, &mask)) {
                return NULL; // Python sets a simple error
@@ -3838,7 +3837,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
        {
                PyErr_Clear();
                
-               if (ConvertPythonToGameObject(pyto, &other, false, ""))  /* error will be overwritten */
+               if (ConvertPythonToGameObject(logicmgr, pyto, &other, false, ""))  /* error will be overwritten */
                {
                        toPoint = other->NodeGetWorldPosition();
                } else
@@ -3855,7 +3854,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
        {
                PyErr_Clear();
                
-               if (ConvertPythonToGameObject(pyfrom, &other, false, "")) /* error will be overwritten */
+               if (ConvertPythonToGameObject(logicmgr, pyfrom, &other, false, "")) /* error will be overwritten */
                {
                        fromPoint = other->NodeGetWorldPosition();
                } else
@@ -4144,7 +4143,7 @@ PyObject *KX_GameObject::Pyget(PyObject *args)
        return def;
 }
 
-bool ConvertPythonToGameObject(PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix)
+bool ConvertPythonToGameObject(SCA_LogicManager *manager, PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix)
 {
        if (value==NULL) {
                PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
@@ -4164,7 +4163,7 @@ bool ConvertPythonToGameObject(PyObject *value, KX_GameObject **object, bool py_
        }
        
        if (PyUnicode_Check(value)) {
-               *object = (KX_GameObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String( _PyUnicode_AsString(value) ));
+               *object = (KX_GameObject*)manager->GetGameObjectByName(STR_String( _PyUnicode_AsString(value) ));
                
                if (*object) {
                        return true;
index a25f999026c586ac175c9d66d00b59faebba918e..9c582d3e27aec6e0cae750c7f0b4f8be79c41684 100644 (file)
@@ -67,7 +67,7 @@ struct bAction;
 
 #ifdef WITH_PYTHON
 /* utility conversion function */
-bool ConvertPythonToGameObject(PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix);
+bool ConvertPythonToGameObject(SCA_LogicManager *logicmgr, PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix);
 #endif
 
 #ifdef USE_MATHUTILS
index c98766c9c81db2d68b631037d15129d1fa21dd76..8da3542b4d6a71a366a8f8c0bdf9e31e446ffc06 100644 (file)
@@ -43,6 +43,8 @@
 
 #include "KX_PyMath.h"
 
+#include "SCA_LogicManager.h"
+
 #include "EXP_PyObjectPlus.h" 
 
 PyTypeObject KX_MeshProxy::Type = {
@@ -405,7 +407,7 @@ PyObject *KX_MeshProxy::pyattr_get_numPolygons(void *self_v, const KX_PYATTRIBUT
 }
 
 /* a close copy of ConvertPythonToGameObject but for meshes */
-bool ConvertPythonToMesh(PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix)
+bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix)
 {
        if (value==NULL) {
                PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
@@ -425,7 +427,7 @@ bool ConvertPythonToMesh(PyObject *value, RAS_MeshObject **object, bool py_none_
        }
        
        if (PyUnicode_Check(value)) {
-               *object = (RAS_MeshObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String( _PyUnicode_AsString(value) ));
+               *object = (RAS_MeshObject*)logicmgr->GetMeshByName(STR_String( _PyUnicode_AsString(value) ));
                
                if (*object) {
                        return true;
index 4a4358bff3ae6e40a45574466ab8501ca5926273..dbd7987f7858f2e73616c9bf771eee84a24f3035 100644 (file)
@@ -36,8 +36,9 @@
 
 #include "SCA_IObject.h"
 
+class SCA_LogicManager;
 /* utility conversion function */
-bool ConvertPythonToMesh(PyObject *value, class RAS_MeshObject **object, bool py_none_ok, const char *error_prefix);
+bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, class RAS_MeshObject **object, bool py_none_ok, const char *error_prefix);
 
 class KX_MeshProxy     : public CValue
 {
index 454366932814dfce8a2950db65467b57452b03ac..8c1dee7940f9688c7fa05c87f9587cf97b305307 100644 (file)
@@ -687,7 +687,7 @@ int KX_ObjectActuator::pyattr_set_reference(void *self, const struct KX_PYATTRIB
        KX_ObjectActuator* actuator = static_cast<KX_ObjectActuator*>(self);
        KX_GameObject *refOb;
        
-       if (!ConvertPythonToGameObject(value, &refOb, true, "actu.reference = value: KX_ObjectActuator"))
+       if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &refOb, true, "actu.reference = value: KX_ObjectActuator"))
                return PY_SET_ATTR_FAIL;
        
        if (actuator->m_reference)
index 6ffa2593792b1440197900ca9ea861cf1bcc2acc..0b133400920bf2d3e276fb14367b78da44d7108e 100644 (file)
@@ -186,7 +186,7 @@ int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE
        KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self);
        KX_GameObject *gameobj;
                
-       if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_ParentActuator"))
+       if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_ParentActuator"))
                return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
                
        if (actuator->m_ob != NULL)
index a0084662490776c9461363c73d71b319f24cf76e..81fe3be1fcf25f3a32b2df0f3e25bcbb6ea4aa5b 100644 (file)
@@ -40,6 +40,7 @@
 #include "MT_Matrix3x3.h"
 
 #include "KX_GameObject.h" // ConvertPythonToGameObject()
+#include "KX_PythonInit.h"
 
 #include "EXP_PyObjectPlus.h" 
 
@@ -472,7 +473,7 @@ static PyObject* gPyGetCharacter(PyObject* self,
        if (!PyArg_ParseTuple(args,"O", &pyob))
                return NULL;
 
-       if (!ConvertPythonToGameObject(pyob, &ob, false, "bge.constraints.getCharacter(value)"))
+       if (!ConvertPythonToGameObject(KX_GetActiveScene()->GetLogicManager(), pyob, &ob, false, "bge.constraints.getCharacter(value)"))
                return NULL;
 
        if (PHY_GetActiveEnvironment())
index fdcfd22270bf7911bbd44d3ed032cbd559d6b849..bb38d8269b72295a74bb1babc14b325580abd477 100644 (file)
@@ -216,7 +216,7 @@ int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYAT
        KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
        KX_GameObject *gameobj;
                
-       if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SCA_AddObjectActuator"))
+       if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SCA_AddObjectActuator"))
                return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
                
        if (actuator->m_OriginalObject != NULL)
index 6b6b090c1c487d80ee4e5eea2d1ef44d615ad55e..1bf76de0b4034c948fa8d2aebd1c11c2466f10c6 100644 (file)
@@ -101,7 +101,7 @@ int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYAT
        KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
        RAS_MeshObject* new_mesh;
        
-       if (!ConvertPythonToMesh(value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator"))
+       if (!ConvertPythonToMesh(actuator->GetLogicManager(), value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator"))
                return PY_SET_ATTR_FAIL;
        
        actuator->m_mesh = new_mesh;
index 9eb9066d56febeb67d801e117d3d81ca5c35535d..a5a418b5e782ed0dfe597476c15ddec11bdc8235 100644 (file)
@@ -1925,6 +1925,7 @@ static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *from, KX_Sce
 
        brick->Replace_IScene(to);
        brick->Replace_NetworkScene(to->GetNetworkScene());
+       brick->SetLogicManager(to->GetLogicManager());
 
        // If we end up replacing a KX_TouchEventManager, we need to make sure
        // physics controllers are properly in place. In other words, do this
@@ -2541,8 +2542,8 @@ KX_PYMETHODDEF_DOC(KX_Scene, addObject,
        if (!PyArg_ParseTuple(args, "O|Oi:addObject", &pyob, &pyreference, &time))
                return NULL;
 
-       if (!ConvertPythonToGameObject(pyob, &ob, false, "scene.addObject(object, reference, time): KX_Scene (first argument)") ||
-               !ConvertPythonToGameObject(pyreference, &reference, true, "scene.addObject(object, reference, time): KX_Scene (second argument)"))
+       if (!ConvertPythonToGameObject(m_logicmgr, pyob, &ob, false, "scene.addObject(object, reference, time): KX_Scene (first argument)") ||
+               !ConvertPythonToGameObject(m_logicmgr, pyreference, &reference, true, "scene.addObject(object, reference, time): KX_Scene (second argument)"))
                return NULL;
 
        if (!m_inactivelist->SearchValue(ob)) {
index af2a2b30b845dbf153f7f099e95e30adfac446a8..d3a7b665e61d91727a22f93d6eadc0c84b8f2e1b 100644 (file)
@@ -579,7 +579,7 @@ int KX_SteeringActuator::pyattr_set_target(void *self, const struct KX_PYATTRIBU
        KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
        KX_GameObject *gameobj;
 
-       if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
+       if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
                return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
 
        if (actuator->m_target != NULL)
@@ -607,7 +607,7 @@ int KX_SteeringActuator::pyattr_set_navmesh(void *self, const struct KX_PYATTRIB
        KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
        KX_GameObject *gameobj;
 
-       if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
+       if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
                return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
 
        if (dynamic_cast<KX_NavMeshObject *>(gameobj) == NULL) {
index 74902ab20ee016f2015bc92c7917908cd39b3591..beccdfaad93db038e6fa5e735e1174acd59db087 100644 (file)
@@ -411,7 +411,7 @@ int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUT
        KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self);
        KX_GameObject *gameobj;
                
-       if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_TrackToActuator"))
+       if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_TrackToActuator"))
                return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
                
        if (actuator->m_object != NULL)
index ee791a44782275c181022a6f4feeca674004b3ab..c1af6de127e70064f4eaf7f0b4c351e2a9b644f4 100644 (file)
@@ -30,6 +30,7 @@
 #include "KX_PyMath.h"
 #include "KX_GameObject.h"
 #include "KX_MotionState.h"
+#include "KX_PythonInit.h"
 
 KX_VehicleWrapper::KX_VehicleWrapper(
                                                PHY_IVehicle* vehicle,
@@ -82,7 +83,7 @@ PyObject *KX_VehicleWrapper::PyAddWheel(PyObject *args)
        if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering))
        {
                KX_GameObject *gameOb;
-               if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)"))
+               if (!ConvertPythonToGameObject(KX_GetActiveScene()->GetLogicManager(), wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)"))
                        return NULL;
 
                if (gameOb->GetSGNode())