[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31342] branches/soc-2010-moguri-2/source/ gameengine/Ketsji/KX_PythonShaders.cpp: Fixed the memcpy crash when storing the original CustomUniform data.
Mitchell Stokes
mogurijin at gmail.com
Sun Aug 15 11:52:09 CEST 2010
Revision: 31342
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31342
Author: moguri
Date: 2010-08-15 11:52:09 +0200 (Sun, 15 Aug 2010)
Log Message:
-----------
Fixed the memcpy crash when storing the original CustomUniform data. Also, setting float and int values now actually changes the underlaying CustomUniform. However, reverting still isn't working since the destructor is not getting called.
Modified Paths:
--------------
branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp
Modified: branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp
===================================================================
--- branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp 2010-08-15 09:34:18 UTC (rev 31341)
+++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp 2010-08-15 09:52:09 UTC (rev 31342)
@@ -219,9 +219,11 @@
m_data = cu->data;
// We copy the original data so we can restore it later
- /*switch(m_type)
+ switch(m_type)
{
case MA_UNF_FLOAT:
+ m_old_data = m_data;
+ break;
case MA_UNF_VEC2:
case MA_UNF_VEC3:
case MA_UNF_VEC4:
@@ -229,6 +231,8 @@
memcpy(m_old_data, m_data, sizeof(float)*m_size);
break;
case MA_UNF_INT:
+ m_old_data = m_data;
+ break;
case MA_UNF_IVEC2:
case MA_UNF_IVEC3:
case MA_UNF_IVEC4:
@@ -239,37 +243,43 @@
m_old_data = malloc(sizeof(Tex));
memcpy(m_old_data, m_data, sizeof(Tex));
break;
- }*/
+ }
}
KX_PythonUniform::~KX_PythonUniform()
{
// Replace the possibly edited data with the original values
- //if (m_cu && m_old_data)
- //{
- // switch(m_type)
- // {
- // case MA_UNF_FLOAT:
- // case MA_UNF_VEC2:
- // case MA_UNF_VEC3:
- // case MA_UNF_VEC4:
- // memcpy(m_data, m_old_data, sizeof(float)*m_size);
- // break;
- // case MA_UNF_INT:
- // case MA_UNF_IVEC2:
- // case MA_UNF_IVEC3:
- // case MA_UNF_IVEC4:
- // memcpy(m_data, m_old_data, sizeof(int)*m_size);
- // break;
- // case MA_UNF_SAMPLER2D:
- // memcpy(m_data, m_old_data, sizeof(Tex));
- // break;
- // }
+ if (m_cu && m_old_data)
+ {
+ switch(m_type)
+ {
+ case MA_UNF_FLOAT:
+ m_cu->data = m_data;
+ break;
+ case MA_UNF_VEC2:
+ case MA_UNF_VEC3:
+ case MA_UNF_VEC4:
+ memcpy(m_data, m_old_data, sizeof(float)*m_size);
+ free(m_old_data);
+ break;
+ case MA_UNF_INT:
+ m_cu->data = m_data;
+ break;
+ case MA_UNF_IVEC2:
+ case MA_UNF_IVEC3:
+ case MA_UNF_IVEC4:
+ memcpy(m_data, m_old_data, sizeof(int)*m_size);
+ free(m_old_data);
+ break;
+ case MA_UNF_SAMPLER2D:
+ memcpy(m_data, m_old_data, sizeof(Tex));
+ free(m_old_data);
+ break;
+ }
- // // Now we can get rid of the old data
- // free(m_old_data);
- //}
+ // Now we can get rid of the old data
+ }
}
PyObject *KX_PythonUniform::py_uniform_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
@@ -412,6 +422,8 @@
}
*(float*)(&self->m_data) = PyFloat_AsDouble(value);
+ if (self->m_cu)
+ self->m_cu->data = self->m_data;
return PY_SET_ATTR_SUCCESS;
}
case MA_UNF_VEC2:
@@ -452,6 +464,8 @@
}
*(int*)(&self->m_data) = PyLong_AsLong(value);
+ if (self->m_cu)
+ self->m_cu->data = self->m_data;
return PY_SET_ATTR_SUCCESS;
}
case MA_UNF_IVEC2:
More information about the Bf-blender-cvs
mailing list