From f999426daaf98c3abdb65ae6b78a9463ebcad0dd Mon Sep 17 00:00:00 2001 From: Michel Selten Date: Thu, 10 Jul 2003 20:00:51 +0000 Subject: [PATCH] * 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. --- source/blender/python/api2_2x/Object.c | 8 ++++---- source/blender/python/api2_2x/matrix.c | 14 ++++++++++++-- source/blender/python/api2_2x/vector.h | 2 +- 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]; + MatrixObject *inverse = (MatrixObject *)newMatrixObject (NULL); + + Mat4Invert (inverse->mem, self->object->obmat); - Mat4Invert (inverse, 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;