bugfix: #1930 Mathutils.Euler constructor fails to initialize class variables
authorStephen Swaney <sswaney@centurytel.net>
Wed, 1 Dec 2004 23:09:59 +0000 (23:09 +0000)
committerStephen Swaney <sswaney@centurytel.net>
Wed, 1 Dec 2004 23:09:59 +0000 (23:09 +0000)
Euler object was holding pointer to bad memory.
Euler now owns internal array memory and frees it in destructor.

source/blender/python/api2_2x/euler.c

index d55b581427098037b269591f975d69eb53cbab7b..6b72460ccd431ccf4f9c9b457fce04a3f9128ca3 100644 (file)
@@ -150,6 +150,9 @@ PyObject *Euler_Zero( EulerObject * self )
 
 static void Euler_dealloc( EulerObject * self )
 {
+       /* since we own this memory... */
+       PyMem_Free( self->eul );
+
        PyObject_DEL( self );
 }
 
@@ -330,13 +333,25 @@ PyObject *newEulerObject( float *eul )
 
        self = PyObject_NEW( EulerObject, &euler_Type );
 
+       /* 
+          we own the self->eul memory and will free it later.
+          if we received an input arg, copy to our internal array
+       */
+
+       self->eul = PyMem_Malloc( 3 * sizeof( float ) );
+       if( ! self->eul )
+               return EXPP_ReturnPyObjError( PyExc_MemoryError,
+                                             "newEulerObject:PyMem_Malloc failed" );
+       
        if( !eul ) {
-               self->eul = PyMem_Malloc( 3 * sizeof( float ) );
                for( x = 0; x < 3; x++ ) {
                        self->eul[x] = 0.0f;
                }
-       } else
-               self->eul = eul;
+       } else{
+               for( x = 0; x < 3; x++){
+                       self->eul[x] = eul[x];
+               }
+       }
 
        return ( PyObject * ) self;
 }