Bug in KX_GameObject.get() and ListValue.get(), wasn't checking if the CValue derived...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 31 May 2009 17:44:38 +0000 (17:44 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 31 May 2009 17:44:38 +0000 (17:44 +0000)
so where foo is an int prop,
 gameOb.get("foo") == 0, would end up returning a CValue int proxy.

This is more a problem for KX_GameObject since ListValues with python access mostly don't contain ints, strings, floats.
This also wont break games from 2.48 since the .get() function wasn't available.

source/gameengine/Expressions/ListValue.cpp
source/gameengine/Ketsji/KX_GameObject.cpp

index c741a6d880987285153d3a4d90041ae6c11b6d4e..a0d73c75d60da9cd16f753809d81e9408d6913d7 100644 (file)
@@ -77,8 +77,13 @@ PyObject* listvalue_mapping_subscript(PyObject* self, PyObject* pyindex)
        if (PyString_Check(pyindex))
        {
                CValue *item = ((CListValue*) list)->FindValue(PyString_AsString(pyindex));
-               if (item)
-                       return item->GetProxy();
+               if (item) {
+                       PyObject* pyobj = item->ConvertValueToPython();
+                       if(pyobj)
+                               return pyobj;
+                       else
+                               return item->GetProxy();
+               }
        }
        else if (PyInt_Check(pyindex))
        {
@@ -575,9 +580,13 @@ PyObject* CListValue::Pyget(PyObject *args)
                return NULL;
        
        CValue *item = FindValue((const char *)key);
-       if (item)
-               return item->GetProxy();
-       
+       if (item) {     
+               PyObject* pyobj = item->ConvertValueToPython();
+               if (pyobj)
+                       return pyobj;
+               else
+                       return item->GetProxy();
+       }
        Py_INCREF(def);
        return def;
 }
index 04b1276569ee4380e872a9237b66352a81ec0dd1..7f417b325c8919d644aef84108b9189a3f4f832e 100644 (file)
@@ -2758,8 +2758,13 @@ PyObject* KX_GameObject::Pyget(PyObject *args)
        
        if(PyString_Check(key)) {
                CValue *item = GetProperty(PyString_AsString(key));
-               if (item)
-                       return item->GetProxy();
+               if (item) {
+                       ret = item->ConvertValueToPython();
+                       if(ret)
+                               return ret;
+                       else
+                               return item->GetProxy();
+               }
        }
        
        if (m_attr_dict && (ret=PyDict_GetItem(m_attr_dict, key))) {