* 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.
This commit is contained in:
2003-07-10 20:00:51 +00:00
parent 66e2bf39d9
commit f999426daa
3 changed files with 17 additions and 7 deletions

View File

@@ -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)

View File

@@ -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);

View File

@@ -66,7 +66,7 @@ typedef struct {
PyObject_VAR_HEAD
PyObject *rows[4];
Matrix4Ptr mat;
Matrix4Ptr mem;
} MatrixObject;