locked
WP7 Silverlight Game Stutters Every Few Seconds. RRS feed

  • Question

  • My wp7 Silverlight game, Krashlander, has a periodic (every few seconds) "stutter".  By stutter, I mean the whole game freezes for a few milliseconds then continues on as normal.

    This stutter seems to occur regardless of framerate.  Even when my game is running consistently at 30+ fps, the stutter still occurs.

    My first thought, especially since wp7 runs on top of the compact framework, was that this had to be a GC issue.

    To test this, I used the code suggested by Shawn Hargreaves:

    WeakReference gcTracker = new WeakReference(new object()); 

    In my Update method:

        if (!gcTracker.IsAlive) 
        { 
            Trace.WriteLine("A garbage collection occurred!"); 
            gcTracker = new WeakReference(new object()); 
        } 


    With this running in my game's update method, no on going garbage collection was found.


    I've read all the wp7/silverlight performance docs multiple times and I've scoured the web for other hints.  So far I have found NOTHING that fixes this issue.

    So, I'm looking for any insight anyone may have on what might be causing this or what I might try to fix it.

    Is it possible GC is occuring that would not be detected by Shawns code? Maybe at a lower level?  It really behaves as though it's a GC issue.

    Has anyone else seen this?


    Desperate for any ideas.

    -Jeff Weber
    www.farseergames.com
    @jeffweber
    Thursday, December 2, 2010 3:04 PM

All replies

  • - what type of timers are you using? how many?
    - are you seeing framerate spikes or memory usage changes during the freeze when you have "Application.Current.Host.Settings.EnableFrameRateCounter = true;"

    I'm working on a WP7 Silverlight game that uses farseer physics and have no freezing (yet?)... (I'm not using the "farseer physics helper" though)
    Thursday, December 2, 2010 6:09 PM
  • I'm using the CompositeTarget.Rendering event to run my game loop.  The framerate jumps around quite a bit, but I handle that in my game loop by running my physics loop seperate from render loop.


    I guess I'm going to have to start from scratch and build toward what I currently have and see when the stutter starts to occur.  Was hoping to avoid doing that.

    How much stuff are  you moving around in  your game?  I'm moving my entire landscape as it's bascially a side scrolling game.

    FYI, I'm not using the helper either.
    Thursday, December 2, 2010 6:40 PM
  • I have seen this behavior in WPF applications using CompositionTarget.Rendering. Some of it was coming from the Rendering events stomping on each other, since it can be called multiple times per frame.

    Here is the workaround I found for it:

            TimeSpan _lastRender = DateTime.Now;  
            private void CompositionTarget_Rendering(object sender, EventArgs e)  
            {  
                RenderingEventArgs args = (RenderingEventArgs)e;  
     
                // only update if some amount of time has passed to avoid multiple calls in the same frame.  
                if (_lastRender != args.RenderingTime)  
                {  
                    BeginScene();  
                    _lastRender = args.RenderingTime;  
                }  
            } 
    Thursday, December 2, 2010 6:52 PM
  • Thanks Foxman.  I will give that a try and report back.
    Thursday, December 2, 2010 9:31 PM
  • What I found regarding the ComponentTarget.Rendering event.  On the phone, this event never seems to run multiple times per frame.  I never get the same RenderTime.  I did notice that the time between calls to this event varies quite a bit.  It's usually in the 19 to 21 range but often jumps to 45 or higher.  My games render loop, I think handles this ok so I don't think this is the issue.

    -Jeff
    Friday, December 3, 2010 2:53 AM
  • So what did you end up using for the game loop?  And how did you run this in a 2nd thread?

    -Jimmy
    Friday, February 11, 2011 4:39 PM