My Application is Possessed by the Devil !!!

Discussion in 'iOS Programming' started by flummoxed, Dec 23, 2010.

  1. flummoxed macrumors member

    Joined:
    Nov 27, 2010
    #1
    This is too weird.

    I am saving a few integer values to a plist for a "saved game state" using the
    applicationDidEnterBackground method .

    I'm saving 6 values, the last 3 of which are created by random generators.
    Sometimes after I close out of the application in the simulator I discover that the previous state of the 3 random values has changed.

    When I open the plist to look at the saved values the last 3 values are 6 6 6.
    I'm not making this up!

    Those 3 values can only be changed by calling the random generation method.
    That method can only be invoked by pressing a button in the UI.
    Whenever the plist gets changed by this behavior it is always 6 6 6, so it can not be coming from the random generator.

    It does not always happen. Only when I close out of the simulator in a specific manner. I don't know if it is from first clicking the home button, and then the red "kill task" button in Xcode, or some other order of operations, but it does not happen all the time.

    Does this sound familiar to anyone or do I need to call an exorcist?
     
  2. rossipoo macrumors regular

    Joined:
    Jun 7, 2009
  3. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #3
    And the timing too - just days before Christmas.

    Anyway, disable multitasking in Info.plist and save those values in -applicationWillTerminate:. See what happens.
     
  4. flummoxed thread starter macrumors member

    Joined:
    Nov 27, 2010
    #4
    Ok, I found the problem...

    When I am saving the values I am saving them from instance variables that store the random numbers. The problem arose when I would quit from the application immediately after opening it. Since the random number method was never invoked, the variables did not get assigned the proper values and remained initialized at 0 from startup.

    So when the plist was being saved it was saving values from an array indexed from the instance variables that where still initialized at zero. The zero indexed values of my arrays just happened to be 6 for no special reason.

    So saving right after opening just saved 0 indexed array values that where 6's.
    Pure coincidence - as most unexplained mysteries usually are.
    I guess I can put away the holy water.

    Incidentally, using -applicationWillTerminate does not seem to be the correct method in iOS 4. I tried that and it would not work. The docs mention that it is proper to use -applicationDidEnterBackground when saving within iOS4 .
     
  5. cnstoll macrumors 6502

    Joined:
    Aug 29, 2010
    #5
    You'd have to actually do that part to make that method work for iOS 4. But it sounds like you solved the problem, and it didn't have anything to do with that anyway.
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    Code:
    [[christ power] compels:you];
    Sorry, had to :D
     
  7. bredell macrumors regular

    Joined:
    Mar 30, 2008
    Location:
    Uppsala, Sweden
    #7
    On the bright side, having your app possessed by the Devil is actually one of the few things that's not forbidden in the App store rules.
     
  8. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #8
    Code:
    [devil openToYourEvilWays: YES];
     
  9. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #9
    LOL! Priceless. Steve Jobs needs to see this!
     

Share This Page