Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

PlayerPrefs not saved in Mac standalone -need help to reprod

Discussion in 'Editor & General Support' started by benblo, Mar 3, 2008.

  1. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Hi!
    We have this very annoying bug: PlayerPrefs are not saved in Mac standalone. They're saved ok in Win standalone, and in the Unity editor, so we know there's no problem with our code.

    We've reproduced it on 4 machines, but UT can't reproduce it. We're wondering if it could be a language issue (all our systems are in French)... seems far-fetched but you never know.

    So if anyone can try our beta and report it here or in PM, we'd be grateful.
    The test is super simple: start the game, enter your name, quit, start again: if it asks for your name again, the PlayerPrefs weren't saved...
    Simply report your OSX version language, and if the test succeeded or not.

    Thanks in advance :p !
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    I'm on 10.4.11 and in American English and it doesn't save. Looking at the plist, nothing is in there besides the internal Unity preferences like resolution and quality settings. However, I'm pretty darn sure other games save fine and if it's how I think they're handling preferences on Mac, it's really simple code.

    If you look at the console.log while the game is running there are exceptions. That's probably the problem and something you just need to fix.
    Code (csharp):
    1. DETAILED EXCEPTION
    2.  
    3. System.NullReferenceException:
    4.   at <0x00000> <unknown method>
    5.   at (wrapper managed-to-native) UnityEngine.Behaviour:set_enabled (bool)
    6.   at PopupBoxBase.Hide () [0x00000]
    7.   at PopupBoxManager.OnLevelWasLoaded () [0x00000]
    8.  
    9. DETAILED EXCEPTION END
    10.  
    11.                     NullReferenceException
    12. PopupBoxBase.Hide ()
    13. PopupBoxManager.OnLevelWasLoaded ()
    14.  
    15. (Filename:  Line: 0)
    Cheers,
    -Jon
     
  3. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Yeah I know it's maddening!!!
    I also have other games that save fine... Anyhoo thanks.

    Still looking for more feedback, especially "working" ones, we seem to have plenty of non-working. We need to figure out in which case it works or doesn't...


    Edit: thanks for the console log, it's due to a new line I added a couple days ago and didn't notice. Unfortunately this PopupBoxManager is only a GUI thing (the window that prompts for the name), and has nothing to do with prefs. I fixed it anyway so thanks ;).

    When you validate your name you'll see the console says
    Code (csharp):
    1.   saving preferences...
    2. UnityEngine.Debug:Log(Object)
    3.  
    4. and then
    5.  
    6. preferences saved!
    7. UnityEngine.Debug:Log(Object)
    8.  
    I put that to make sure that the function where I call PlayerPrefs.SetInt/String etc is called ok.

    Anyway, again, it works on windows so I really think this is a problem with the engine, not my scripts.
     
  4. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    It doesn't save the name here, but that's probably because it crashes every time I try to quit. The relevant part of the crash log is as follows:

    Code (csharp):
    1. Process:         Besmashed [180]
    2. Path:            /Volumes/Data/Downloads/ Unity/Besmashed-mac.app/Contents/MacOS/Besmashed
    3. Identifier:      unity.Gamepulp.Besmashed
    4. Version:         UnityPlayer version 2.0.2f2 (2.0.2f2)
    5. Code Type:       X86 (Native)
    6. Parent Process:  launchd [96]
    7.  
    8. Date/Time:       2008-03-03 09:38:37.361 +0000
    9. OS Version:      Mac OS X 10.5.2 (9C31)
    10. Report Version:  6
    11.  
    12. Exception Type:  EXC_CRASH (SIGABRT)
    13. Exception Codes: 0x0000000000000000, 0x0000000000000000
    14. Crashed Thread:  6
    15.  
    16. <other threads snipped>
    17.  
    18. Thread 6 Crashed:
    19. 0   libSystem.B.dylib               0x92835e35 nanosleep$NOCANCEL$UNIX2003 + 0
    20. 1   libSystem.B.dylib               0x928281b7 usleep$NOCANCEL$UNIX2003 + 61
    21. 2   libSystem.B.dylib               0x928499bb abort + 85
    22. 3   libglib-2.0.0.dylib             0x016d4bc1 g_logv + 1074
    23. 4   libglib-2.0.0.dylib             0x016d4c47 g_log + 41
    24. 5   libmono.0.dylib                 0x015d66f1 SetLastError + 129
    25. 6   libmono.0.dylib                 0x015e9e8b WaitForSingleObjectEx + 73
    26. 7   libmono.0.dylib                 0x015c8c38 ves_icall_System_Threading_ThreadPool_GetMinThreads + 1244
    27. 8   libmono.0.dylib                 0x015ce0a8 mono_thread_init_apartment_state + 297
    28. 9   libmono.0.dylib                 0x015e991f ExitThread + 467
    29. 10  libmono.0.dylib                 0x015ffef0 GC_start_routine + 93
    30. 11  libSystem.B.dylib               0x92785c55 _pthread_start + 321
    31. 12  libSystem.B.dylib               0x92785b12 thread_start + 34
    32.  
    33. Thread 6 crashed with X86 Thread State (32-bit):
    34.   eax: 0xb0550888  ebx: 0x9284996f  ecx: 0x00000000  edx: 0x00000000
    35.   edi: 0x00000002  esi: 0x00002710  ebp: 0xb0550898  esp: 0xb055086c
    36.    ss: 0x0000001f  efl: 0x00010202  eip: 0x92835e35   cs: 0x00000017
    37.    ds: 0x0000001f   es: 0x0000001f   fs: 0x0000001f   gs: 0x00000037
    38.   cr2: 0x016d70d6
    I can post the rest of the crash log if that's helpful.

    I'm running 10.5.2 in English.
     
  5. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Sorry, I sneakily updated my post with more information probably as you were responding... I have a bad habit of doing that. :D I found the likely problem.

    -Jon
     
  6. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Saw that... responded above... unfortunately it's not the likely problem ;)
     
  7. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    So it crashes on Leopard... never saw that here (we're on 10.4.11).

    What I do get on quit is this:
    Code (csharp):
    1. Cleanup player
    2.  
    3. ** ERROR **: file error.c: line 62 (SetLastError): assertion failed: (ret == 0)
    4. aborting...
    5.  
    Unfortunately that doesn't point to any .NET code so I really have no idea what to do with it...

    I don't know if prefs are supposed to be physically saved every time you use PlayerPrefs.SetXXX, or only once when you quit the app.
     
  8. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    I believe Unity directly uses OSX's standard preferences API, which caches the changes in memory until the application quits. If you crash while quitting, they won't get written.

    It would be possible for Unity to explicitly flush the changes to disk on every change with this particular API, but that won't solve your crash bug. ;)
     
  9. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Thanks for the info, great stuff!
    If they indeed use an OSX API, it feels less and less likely that language is the issue, I don't see Apple messing that up.

    About the "quit crash", the only place I could see it come from is this one script that uses OnApplicationQuit.
    I just removed it uploaded a new version: could you be so kind as to check it (same location), see if it still crashes?

    To Jonathan : I also fixed the popup bug thing, but it still fails to save...
     
  10. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    I'm getting exactly the same behaviour with the new build, unfortunately.

    Are you doing anything with threads in your game? The stack trace in the log snippet I posted makes me wonder if you're using threads in a way that makes the garbage collection routine crash. Unfortunately, I don't know enough about the intricacies of threading to have more than a hunch about that.

    In case it helps, the full console log (minus datestamps etc. for terseness) for your game looks like this:

    Code (csharp):
    1. Besmashed[330] Player: init engine
    2. Besmashed[330] Could not find image named 'ScreenSelector'.
    3. Besmashed[330] DETAILED EXCEPTION
    4. Besmashed[330] System.NullReferenceException:  
    5. Besmashed[330]   at <0x00000> <unknown method>
    6. Besmashed[330]   at (wrapper managed-to-native) UnityEngine.Behaviour:set_enabled (bool)
    7. Besmashed[330]   at PopupBoxBase.Hide () [0x00000]  
    8. Besmashed[330]   at PopupBoxManager.OnLevelWasLoaded () [0x00000]  
    9. Besmashed[330] DETAILED EXCEPTION END
    10. Besmashed[330]                     NullReferenceException
    11. Besmashed[330] PopupBoxBase.Hide ()  
    12. Besmashed[330] PopupBoxManager.OnLevelWasLoaded ()  
    13. Besmashed[330]  
    14. Besmashed[330] (Filename:  Line: 0)
    15. Besmashed[330] ----UnityEngine.Debug:Internal_Log(Int32, String, Object)
    16. Besmashed[330] ----UnityEngine.Debug:Internal_Log(Int32, String, Object)
    17. Besmashed[330] ----UnityEngine.Debug:Log(Object)
    18. Besmashed[330] ----Preferences:Save()
    19. Besmashed[330] ----Preferences:saveFirstTimer(Hashtable)
    20. Besmashed[330] ----FormBox:ButtonClicked(String)
    21. Besmashed[330] ----PopupBoxBase:drawButtons()
    22. Besmashed[330] ----PopupBoxBase:drawBox(Int32)
    23. Besmashed[330] ----System.MulticastDelegate:invoke_void_int(Int32)
    24. Besmashed[330] ----UnityEngine.LayoutedWindow:DoWindow(Int32)
    25. Besmashed[330] ----UnityEngine._Window:Do()
    26. Besmashed[330] ----UnityEngine.GUI:BeginWindows(Event, Int32)
    27. Besmashed[330]   saving preferences...
    28. Besmashed[330] UnityEngine.Debug:Log(Object)
    29. Besmashed[330] Preferences:Save()
    30. Besmashed[330] Preferences:saveFirstTimer(Hashtable)
    31. Besmashed[330] FormBox:ButtonClicked(String)
    32. Besmashed[330] PopupBoxBase:drawButtons()
    33. Besmashed[330] PopupBoxBase:drawBox(Int32)
    34. Besmashed[330] UnityEngine.GUI:BeginWindows(Event, Int32)
    35. Besmashed[330]  
    36. Besmashed[330] (Filename: /Users/unity-build/Desktop/automatic-build-2/unity/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 1567)
    37. Besmashed[330] ----UnityEngine.Debug:Internal_Log(Int32, String, Object)
    38. Besmashed[330] ----UnityEngine.Debug:Internal_Log(Int32, String, Object)
    39. Besmashed[330] ----UnityEngine.Debug:Log(Object)
    40. Besmashed[330] ----Preferences:Save()
    41. Besmashed[330] ----Preferences:saveFirstTimer(Hashtable)
    42. Besmashed[330] ----FormBox:ButtonClicked(String)
    43. Besmashed[330] ----PopupBoxBase:drawButtons()
    44. Besmashed[330] ----PopupBoxBase:drawBox(Int32)
    45. Besmashed[330] ----System.MulticastDelegate:invoke_void_int(Int32)
    46. Besmashed[330] ----UnityEngine.LayoutedWindow:DoWindow(Int32)
    47. Besmashed[330] ----UnityEngine._Window:Do()
    48. Besmashed[330] ----UnityEngine.GUI:BeginWindows(Event, Int32)
    49. Besmashed[330] preferences saved!
    50. Besmashed[330] UnityEngine.Debug:Log(Object)
    51. Besmashed[330] Preferences:Save()
    52. Besmashed[330] Preferences:saveFirstTimer(Hashtable)
    53. Besmashed[330] FormBox:ButtonClicked(String)
    54. Besmashed[330] PopupBoxBase:drawButtons()
    55. Besmashed[330] PopupBoxBase:drawBox(Int32)
    56. Besmashed[330] UnityEngine.GUI:BeginWindows(Event, Int32)
    57. Besmashed[330]  
    58. Besmashed[330] (Filename: /Users/unity-build/Desktop/automatic-build-2/unity/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 1567)
    59. Besmashed[330] Cleanup player
    60. Besmashed[330] ** ERROR **: file error.c: line 62 (SetLastError): assertion failed: (ret == 0)
    61. Besmashed[330] aborting...
    62. launchd[96] ([0x0-0x38038].unity.Gamepulp.Besmashed[330]) Exited abnormally: Abort trap0x38038].unity.Gamepulp.Besmashed[330]) Exited abnormally: Abort trap
    So, from what you've already said, it sounds like on Leopard, exactly the same thing happens as on Tiger, except the app also crashes.
     
  11. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    S*** sorry I messed up, didn't upload the app correctly :s. Now it's ok.
    I noticed cause you still had the popup bug in the log.

    No, I'm not doing anything with threads.

    Thanks for the full transcript. You seem to be right, you still have the assertion failed thing on leopard, but on top of that you got
    Code (csharp):
    1. launchd[96] ([0x0-0x38038].unity.Gamepulp.Besmashed[330]) Exited abnormally: Abort trap0x38038].unity.Gamepulp.Besmashed[330]) Exited abnormally: Abort trap
    So really the PlayerPrefs thing is probably only a side-effect of this crash.

    BTW the console seems better on leopard, with thread name (+ timestamp you say?)... have to update one of these days...
     
  12. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    I'd test it again, but I'm at work now, and we only have Tiger machines here. I can try again when I get home if you like.

    It's kinda better, but it apparently has quite a lot of latency between when an app posts a message and when it actually appears in the log, especially when a lot of logging is going on. Also, they've cleverly altered it so that you can't select and copy part of a line from the main console listing; you can only select whole lines.

    That's progress!
     
  13. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Finally found the problem, yay!!
    Neil, you put me on the right track: I wasn't explicitly using threads, but sockets, so I guess something similar was going on.

    Anyway I managed to fixed it so thanks for your help all!
     
  14. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    Pleased to hear that. :)