[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31340] branches/soc-2010-moguri-2/source: Resolving a crash when the image isn't found for a Texture.

Mitchell Stokes mogurijin at gmail.com
Sun Aug 15 11:08:37 CEST 2010


Revision: 31340
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31340
Author:   moguri
Date:     2010-08-15 11:08:37 +0200 (Sun, 15 Aug 2010)

Log Message:
-----------
Resolving a crash when the image isn't found for a Texture.

Also, the Python Uniform's size is now being properly set even if it's not constructed from a CustomUniform. Also, if an improper type is supplied, an error is now raised.

There is also some commented out code for trying to deal with reseting the CustomUniform values back to their original values.

Modified Paths:
--------------
    branches/soc-2010-moguri-2/source/blender/gpu/intern/gpu_material.c
    branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp
    branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h

Modified: branches/soc-2010-moguri-2/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/soc-2010-moguri-2/source/blender/gpu/intern/gpu_material.c	2010-08-15 08:53:28 UTC (rev 31339)
+++ branches/soc-2010-moguri-2/source/blender/gpu/intern/gpu_material.c	2010-08-15 09:08:37 UTC (rev 31340)
@@ -440,8 +440,11 @@
 				if (tex)
 				{
 					gtex = GPU_texture_from_blender(tex->ima, &tex->iuser, 1.0, 0);
-					GPU_texture_bind(gtex, 3);
-					GPU_shader_uniform_texture(shader, loc, gtex);
+					if (gtex)
+					{
+						GPU_texture_bind(gtex, 3);
+						GPU_shader_uniform_texture(shader, loc, gtex);
+					}
 				}
 			}
 		}
@@ -526,7 +529,7 @@
 				if (tex)
 				{
 					gtex = GPU_texture_from_blender(tex->ima, &tex->iuser, 1.0, 0);
-					GPU_texture_unbind(gtex);
+					if (gtex) GPU_texture_unbind(gtex);
 				}
 			}
 		}

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 08:53:28 UTC (rev 31339)
+++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.cpp	2010-08-15 09:08:37 UTC (rev 31340)
@@ -198,37 +198,114 @@
  * The Uniform type
  */
 
-KX_PythonUniform::KX_PythonUniform(char* name, short type)
+KX_PythonUniform::KX_PythonUniform(char* name, short type, int size)
 	: PyObjectPlus(),
 	m_name(name),
 	m_type(type),
-	m_data(NULL)
+	m_size(size),
+	m_data(NULL),
+	m_cu(NULL),
+	m_old_data(NULL)
 {
 }
 
 KX_PythonUniform::KX_PythonUniform(CustomUniform *cu)
-	: PyObjectPlus()
+	: PyObjectPlus(),
+	m_cu(cu)
 {
 	m_name = cu->name;
 	m_type = cu->type;
 	m_size = cu->size;
 	m_data = cu->data;
+
+	// We copy the original data so we can restore it later
+	/*switch(m_type)
+	{
+	case MA_UNF_FLOAT:
+	case MA_UNF_VEC2:
+	case MA_UNF_VEC3:
+	case MA_UNF_VEC4:
+		m_old_data = malloc(sizeof(float)*m_size);
+		memcpy(m_old_data, m_data, sizeof(float)*m_size);
+		break;
+	case MA_UNF_INT:
+	case MA_UNF_IVEC2:
+	case MA_UNF_IVEC3:
+	case MA_UNF_IVEC4:
+		m_old_data = malloc(sizeof(int)*m_size);
+		memcpy(m_old_data, m_data, sizeof(int)*m_size);
+		break;
+	case MA_UNF_SAMPLER2D:
+		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;
+	//	}
+
+	//	// Now we can get rid of the old data
+	//	free(m_old_data);
+	//}
 }
 
 PyObject *KX_PythonUniform::py_uniform_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
 	char *name;
 	short type_const;
+	int size;
 
 	if (!PyArg_ParseTuple(args, "sh:Uniform", &name, &type_const))
 		return NULL;
+	
+	switch(type_const)
+	{
+		case MA_UNF_FLOAT:
+		case MA_UNF_INT:
+		case MA_UNF_SAMPLER2D:
+			size = 1;
+			break;
+		case MA_UNF_VEC2:
+		case MA_UNF_IVEC2:
+			size = 2;
+			break;
+		case MA_UNF_VEC3:
+		case MA_UNF_IVEC3:
+			size = 3;
+			break;
+		case MA_UNF_VEC4:
+		case MA_UNF_IVEC4:
+			size = 4;
+			break;
+		default:
+			PyErr_SetString(PyExc_ValueError, "the supplied type is unsupported");
+			return NULL;
+	}
 
-	KX_PythonUniform* pyuniform = new KX_PythonUniform(name, type_const);
+	KX_PythonUniform* pyuniform = new KX_PythonUniform(name, type_const, size);
 	return pyuniform->NewProxy(true);
 }
 

Modified: branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h
===================================================================
--- branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h	2010-08-15 08:53:28 UTC (rev 31339)
+++ branches/soc-2010-moguri-2/source/gameengine/Ketsji/KX_PythonShaders.h	2010-08-15 09:08:37 UTC (rev 31340)
@@ -73,8 +73,12 @@
 	int m_size;
 	void *m_data;
 
+	/* These are used so we can restore the original data to the Custom Uniform when the engine is done */
+	struct CustomUniform *m_cu;
+	void *m_old_data; 
+
 public:
-	KX_PythonUniform(char* name, short type);
+	KX_PythonUniform(char* name, short type, int size);
 	KX_PythonUniform(struct CustomUniform *cu);
 	~KX_PythonUniform();
 





More information about the Bf-blender-cvs mailing list