Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichel Selten <michel@mselten.demon.nl>2003-07-11 00:00:51 +0400
committerMichel Selten <michel@mselten.demon.nl>2003-07-11 00:00:51 +0400
commitf999426daaf98c3abdb65ae6b78a9463ebcad0dd (patch)
tree95ed54d0c681ab04fc79f4cb4fee81807420e61b
parent66e2bf39d975fe289b60f918f7e23157f22db1f6 (diff)
* Object_getInverseMatrix now returns a correct matrix.
The problem was that the memory was allocated at the stack, but after the Python object was created, the pointer to the memory goes invalid. Thanks to Kester Maddoc for providing a patch - almost 2 weeks ago. Ouch, I should read my mail a little bit better.
-rw-r--r--source/blender/python/api2_2x/Object.c8
-rw-r--r--source/blender/python/api2_2x/matrix.c14
-rw-r--r--source/blender/python/api2_2x/vector.h2
3 files changed, 17 insertions, 7 deletions
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index 7f447f8e2d0..16c192be1a7 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -697,11 +697,11 @@ static PyObject *Object_getEuler (BPy_Object *self)
static PyObject *Object_getInverseMatrix (BPy_Object *self)
{
- float inverse[4][4];
-
- Mat4Invert (inverse, self->object->obmat);
+ MatrixObject *inverse = (MatrixObject *)newMatrixObject (NULL);
+
+ Mat4Invert (inverse->mem, self->object->obmat);
- return (newMatrixObject (inverse));
+ return ((PyObject *)inverse);
}
static PyObject *Object_getLocation (BPy_Object *self, PyObject *args)
diff --git a/source/blender/python/api2_2x/matrix.c b/source/blender/python/api2_2x/matrix.c
index 6694ae8adab..76d4409dbad 100644
--- a/source/blender/python/api2_2x/matrix.c
+++ b/source/blender/python/api2_2x/matrix.c
@@ -39,6 +39,8 @@ static void Matrix_dealloc (MatrixObject *self)
Py_DECREF (self->rows[2]);
Py_DECREF (self->rows[3]);
+ if (self->mem)
+ PyMem_Free (self->mem);
PyMem_DEL (self);
}
@@ -130,8 +132,16 @@ PyObject * newMatrixObject (float mat[][4])
MatrixObject * self;
self = PyObject_NEW (MatrixObject, &Matrix_Type);
- self->mat = mat;
-
+ if (mat)
+ {
+ self->mem = NULL;
+ self->mat = mat;
+ }
+ else
+ {
+ self->mem = PyMem_Malloc (4*4*sizeof (float));
+ self->mat = self->mem;
+ }
self->rows[0] = newVectorObject ((float *)(self->mat[0]), 4);
self->rows[1] = newVectorObject ((float *)(self->mat[1]), 4);
self->rows[2] = newVectorObject ((float *)(self->mat[2]), 4);
diff --git a/source/blender/python/api2_2x/vector.h b/source/blender/python/api2_2x/vector.h
index 8969bed5fb4..2e0250c3a07 100644
--- a/source/blender/python/api2_2x/vector.h
+++ b/source/blender/python/api2_2x/vector.h
@@ -66,7 +66,7 @@ typedef struct {
PyObject_VAR_HEAD
PyObject *rows[4];
Matrix4Ptr mat;
-
+ Matrix4Ptr mem;
} MatrixObject;