daniel955 7 Light Poster

I am using VS2008 with TaoFramework's freeglut and OpenGl

Can someone help me? I always get "CallbackOnCollectedDelegate" error
when I apply this rotation and scaling with mouse and timer
on my 3D Tetris game project,

but if I don't apply timer the scale and rotate will be out of control....

these are the codes that cause my tetris game to crash; when playing for some time my game crashes...
when I remove rotate and scale option game doesnt crash...

#region ScaleRotate(int value)
        private static void ScaleRotate(int value)
        {
            if (shiftButton == true) // holding shift button??
            {
                if (lmd == 1 && moving == 1) // is left mouse down? is mouse moving?
                {
                    if (xNw > baseX) // mouse moves to the right
                    {
                        Gl.glScaled(1.07, 1.07, 1.07); //scale bigger
                        baseX = xNw; // update mouse position
                    }
                    else if (xNw < baseX) // moves to the left
                    {
                        Gl.glScaled(0.93, 0.93, 0.93); //smaller
                        baseX = xNw;
                    }
                }
            }
            else if (shiftButton == false) //if not holding the shift
            {
                if (lmd != 0 || rmd != 0 || mmd != 0)//if mouse button is being pressed
                {
                    Gl.glRotated(angle, lmd, mmd, rmd); //rotate
                    if (release == true) //if mouse is released
                    {
                        angle -= 0.09f; //apply persistence
                        if (angle <= 0) //if angle reaches 0
                        {
                            release = false; //stop the release  event
                            lmd = 0; rmd = 0; mmd = 0; //stop rotating
                            angle = 2; //prepare angle for next event
                        }
                    }
                }
            }
           
            RegisterTimer2(); //loop timer
        }
 #endregion ScaleRotate(int value)

 #region RegisterTimer2
        private static void RegisterTimer2()
        {
            Glut.glutTimerFunc(50, new Glut.TimerCallback(ScaleRotate), 1);
        }
 #endregion RegisterTimer2

the error message is:
A callback was made on a garbage collected delegate of type 'Tao.FreeGlut!Tao.FreeGlut.Glut+TimerCallback::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

I am wondering what I am doing wrong and is there any way to optimize my code??

thanks in advanced.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.