Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11855 Posts in 1569 Topics- by 3058 Members - Latest Member: xynewhand

12. February 2012, 01:40:01 AM
Xith3D CommunityGeneral CategoryBugs (Moderator: Marvin Fröhlich)GroupRotator memory leak
Pages: [1]
Print
Author Topic: GroupRotator memory leak  (Read 455 times)
horati
Global Moderator
Getting respectable
*****
Offline Offline

Posts: 393


View Profile
« on: 13. December 2009, 02:45:36 PM »

In GroupRotator
Code:
    private Matrix3f rotMatX = new Matrix3f(),
                     rotMatY = new Matrix3f(),
                     rotMatZ = new Matrix3f(),
                     rotMat  = new Matrix3f();
...
    public boolean animate( long gameTime, long frameTime, TimingMode timingMode )
    {
        if ( !isAnimating() || ( getNumTransformNodes() == 0 ) )
            return ( false );
       
        final long micros = timingMode.getMicroSeconds( gameTime );
       
        if ( getTransformationDirectives().isDirty() )
        {
            setTransformationDirectives( getTransformationDirectives() );
        }
       
        if ( getTransformationDirectives().getUserAxis() == null )
        {
            final float x = angleX.getValue( micros );
            final float y = angleY.getValue( micros );
            final float z = angleZ.getValue( micros );
            final float sin_x = FastMath.sin( x );
            final float cos_x = FastMath.cos( x );
            final float sin_y = FastMath.sin( y );
            final float cos_y = FastMath.cos( y );
            final float sin_z = FastMath.sin( z );
            final float cos_z = FastMath.cos( z );
           
            /*
            t3dMain.setRotation( angleX.getValue( micros ),
                                 angleY.getValue( micros ),
                                 angleZ.getValue( micros ) );
            */

            rotMatX.set( 1f, 0f, 0f, 0f, cos_x, -sin_x, 0f, sin_x, cos_x );
            rotMatY.set( cos_y, 0f, sin_y, 0f, 1f, 0f, -sin_y, 0f, cos_y );
            rotMatZ.set( cos_z, -sin_z, 0f, sin_z, cos_z, 0f, 0f, 0f, 1f );
           
            switch ( getTransformationDirectives().getAxisOrder() )
            {
                case XYZ:
                    rotMatX.mul( rotMatY );
                    rotMatX.mul( rotMatZ );
                    rotMat = rotMatX;
                    break;
                case XZY:
                    rotMatX.mul( rotMatZ );
                    rotMatX.mul( rotMatY );
                    rotMat = rotMatX;
                    break;
                case YXZ:
                    rotMatY.mul( rotMatX );
                    rotMatY.mul( rotMatZ );
                    rotMat = rotMatY;
                    break;
                case YZX:
                    rotMatY.mul( rotMatZ );
                    rotMatY.mul( rotMatY );
                    rotMat = rotMatY;
                    break;
                case ZXY:
                    rotMatZ.mul( rotMatX );
                    rotMatZ.mul( rotMatY );
                    rotMat = rotMatZ;
                    break;
                case ZYX:
                    rotMatZ.mul( rotMatY );
                    rotMatZ.mul( rotMatX );
                    rotMat = rotMatZ;
                    break;
            }
        }
...
    }

causes a memory leak because rotMat gets discarded by each of the switch cases.
Logged

Kevin
"It may not seem like a big deal, but ignorance of character encoding issues leads to insidious code rot akin to y2k."
http://stackoverflow.com/users/3474/sylvarking
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #1 on: 13. December 2009, 09:07:29 PM »

I don't see, how this could cause a memory leak. But there is indeed an unused and discarded Matrix3f instance for some cases. I have fixed that.

Marvin
Logged
horati
Global Moderator
Getting respectable
*****
Offline Offline

Posts: 393


View Profile
« Reply #2 on: 13. December 2009, 11:39:25 PM »

Sorry.  Of course, you are correct.  I meant to say that an object was made available for collection unnecessarily.
Logged

Kevin
"It may not seem like a big deal, but ignorance of character encoding issues leads to insidious code rot akin to y2k."
http://stackoverflow.com/users/3474/sylvarking
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic