Search Unity

Flash: PlayerLoop called recursively!

Discussion in 'Flash' started by akasurreal, Dec 31, 2011.

  1. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Ok so I only have one major issue preventing our game (Mummy's Treasure) from working properly in Flash. We are using SpriteManager and whenever it calls its function to sort the arraylist for draworder, Flash spits this out endlessly, and the game stops running besides music:

    Code (csharp):
    1. PlayerLoop called recursively!
    2. LogCallStackError
    3.     at com.unity::UnityNative$/Ext_Flash_LogCallstack()
    4.     at com.unity::UnityNative$/_Z17DebugStringToFilePKciS0_iiii()
    5.     at com.unity::UnityNative$/_Z10PlayerLoopbb()
    6.     at com.unity::UnityNative$/NativeExt_PlayerLoop()
    7.     at com.unity::UnityContentInternal/playerLoop()
    8.     at com.unity::UnityContent/onEnterFrame()
    9. PlayerLoop called recursively!
    If I comment out the sort everything works fine but half my sprites are hidden because the sort is not happening.

    Here are the relevant bits of code from SpriteManager:

    Code (csharp):
    1.    
    2.     protected SpriteDrawLayerComparer drawOrderComparer = new SpriteDrawLayerComparer(); // Used to sort our draw order array
    3.  
    4.     public void SortDrawingOrder()
    5.     {
    6.         Sprite s;
    7.  
    8.         spriteDrawOrder.Sort(drawOrderComparer);
    9.     ...
    10.     ...
    11.     }
    12.  
    13. // Compares drawing layers of sprites
    14. public class SpriteDrawLayerComparer : IComparer
    15. {
    16.     static Sprite s1;
    17.     static Sprite s2;
    18.  
    19.     int IComparer.Compare(object a, object b)
    20.     {
    21.         s1 = (Sprite)a;
    22.         s2 = (Sprite)b;
    23.        
    24.         if (s1.drawLayer > s2.drawLayer)
    25.             return 1;
    26.         else if (s1.drawLayer < s2.drawLayer)
    27.             return -1;
    28.         else
    29.             return 0;
    30.     }
    31. }
    32.  
    This code obviously works fine under any other platform and for many hundreds/thousands of people that have used SpriteManager in their projects. So this is something Flash related, but I am completely stumped on what to do here. I have done null checks to be sure nothing like that is happening.

    Thanks for any help!
     
  2. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Just a little update, I tried placing a debug.log in the Compare function and it's not even getting hit before this issue starts. Very confused!

    Edit: I also just tried to implement IComparable on the Sprite class and call .Sort() instead of using IComparer. This works fine in Editor but in Flash, the Sprite.IComparable.CompareTo() is never called.

    Is ArrayList.Sort just completely broken in Flash? And if so, how else can I sort this??
     
    Last edited: Dec 31, 2011
  3. Lucas Meijer_old

    Lucas Meijer_old

    Joined:
    Apr 5, 2008
    Posts:
    436
    This will work in the next build. Until then, I suggest trying to see if List<T>'s sort actually works for your case, and if that doesn't work, try Array.Sort, and if that doens't work, implement your own sorter for the time being.
     
  4. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Ah duh, thanks, yeah List<T> fixed it, woo! I think the game is pretty much ready to go now.
     
  5. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    744
    Posts
    8
    Posted: 01:42 AM 1 Minute Ago
    I had a similar issue,

    i was getting the player loop recursive bug when inside of a loop of a Dictionary, and i was at say number 62 key entry, and when i tried to access that 62 using DictionaryHere[pair.key].MyPropertiesHere

    it would cause the error

    instead i had to call pair.value.MyPropertiesHere

    which IS better, however what i was doing before was not recursive and thats a horrible bug that they should fix. this only occurs in the Flash Export version, works fine in editor and web player.
     
  6. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey, so you are not getting a compile error for Sprite Manager that does this:

    This is the only compiler problem I have left at the moment but I don't know what it means. You said you are using Sprite Manager so I am curious as to how you got it to compile and mine won't.
     
  7. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    My project is using SpriteManager1, I haven'tr tried one with SM2 yet. Open SpriteRoot.as file it references and go to the line 323 and see what the line is doing, it should help you match that to the line in the original SpriteRoot.cs file and see about doing what it's doing another way.