Hi, I think i have discovered a big bug. 

This is my original code, working fine in Windows Phone 7

     void Test()
     {
            LanzarAccion("scene",99,'S');
      }

       public void LanzarAccion(string sceneName, int endAction, char tipo)
        {
            // Si lanzo una acción, es que no pudo regresar todavía
            puedeRegresarEscenaAnterior = false;

            Scene scene = LogicCult.SceneFromString(sceneName);

            if (scene == currentAction.Scene) return;

            // Busco la animación
            MovieAnimation animation = LogicCult.FindByScene(scene);

            // Si tenemos una animación de entrada, cambiamos la escena que
quiero ejecutar por la de entrada
            if (sceneEntrada != null)
            {
                scene = LanzaEscenaDeEntrada(); return;
            }
            else
            {
                // Busco el EndAction, para averiguar a qué escena hay que
saltar si termina la animación
                SensorStateSceneCollection<GyroScopePitchRollSensorScene>
sceneCollection = null;

                if (tipo == 'P')
                {
                    sceneCollection = PitchSensorSceneCollection;
                    currentAction.Module = PitchModule;
                }
                if (tipo == 'R')
                {
                    sceneCollection = RollSensorSceneCollection;
                    currentAction.Module = RollModule;
                }

                if (sceneCollection != null)
                {
                    GyroScopePitchRollSensorScene endActionLine =
sceneCollection.Where((c) => c.State == endAction).FirstOrDefault();

                    if (endActionLine != null)
                    {
                        // Si es la animación 99, es la de entrada
                        if (endAction == 99) sceneEntrada =
endActionLine.Scene;
                        else
                            animation.OnEnd = (anim) => { anim.OnEnd = null;
LanzarAccion(endActionLine.Scene, endActionLine.EndAction, tipo); };
                    }
                }
                else
                {
                    currentAction.Module = ShakeModule;

                    // Shake
                    ShakeStateScene endActionLine =
ShakeCollection.Where((c) => c.State == endAction).FirstOrDefault();

                    if (endActionLine != null)
                    {
                        // Si es la animación 99, es la de entrada
                        if (endAction == 99) sceneEntrada =
endActionLine.Scene;
                        else
                            animation.OnEnd = (anim) => { anim.OnEnd = null;
LanzarAccion(endActionLine.Scene, endActionLine.EndActionFalse, tipo); };
                    }
                }
            }

            currentAction.Scene = scene;

            onAction(currentAction);

        }

I was getting problems with monotouch, so i debugged the code. My surprise
was that when the debugger arrives to :


                if (sceneCollection != null)
                {
                    GyroScopePitchRollSensorScene endActionLine =
sceneCollection.Where((c) => c.State == endAction).FirstOrDefault();

                    if (endActionLine != null)
                    {
                        // Si es la animación 99, es la de entrada
                        if (endAction == 99) sceneEntrada =
endActionLine.Scene;
                        else
                            animation.OnEnd = (anim) => { anim.OnEnd = null;
LanzarAccion(endActionLine.Scene, endActionLine.EndAction, tipo); };
                    }
                }
                else

And sceneCollection is null, it jumps to :

                            animation.OnEnd = (anim) => { anim.OnEnd = null;
LanzarAccion(endActionLine.Scene, endActionLine.EndAction, tipo); };

THIS IS WRONG!!! It seems that the { } in the anonimous method are confusing
the compiler.

I have changed all this code by a method like:


               if (sceneCollection != null)
                {
                          Do();
               }

And now it works!!!! 


Uau!!! this can be very anoying because it's a bug very difficult to
trace!!!!


--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/Very-importante-Bug-with-anonimous-functions-tp4600385.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to